3
我有一个ListboxSelect事件绑定到我的列表框中,我正在使用selection_set来选择列表框中的一个项目,但绑定的函数不能运行。当我使用selection_set在列表框中选择一个项目以及单击它时,如何使该功能运行?Tkinter - 在选择列表框时运行事件函数
import tkinter as tk
class SampleApp(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
self.lb = tk.Listbox(self)
for x in range(20):
self.lb.insert("end", x)
self.lb.bind("<<ListboxSelect>>", self.OnSelect)
self.lb.pack(side="top", fill="both", expand=True)
def OnSelect(self, event):
print(event.widget.get(event.widget.curselection()[0]))
self.lb.selection_set(10)
if __name__ == "__main__":
app = SampleApp()
app.mainloop()
即使它不是直接用Python写的,这可能是相关的。 http://wiki.tcl.tk/13939 – Lafexlos
@Lafexlos谢谢你,让它工作,我离开解决方案作为答案。 – simpleguy