python - Tkinter - Run Event Function Upon Listbox Selection -


i have listboxselect event binding listbox, lb. using selection_set select item in listbox, binded function doesn't run. how can make function run when select item in listbox using selection_set when clicked?

import tkinter tk  class sampleapp(tk.tk):     def __init__(self, *args, **kwargs):         tk.tk.__init__(self, *args, **kwargs)         self.lb = tk.listbox(self)          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() 

thanks lafexlos pointing me resource: http://wiki.tcl.tk/13939

what understood have generate virtual event discovered can done in tkinter using event_generate.

self.lb.event_generate("<<listboxselect>>") 

the above line can used generate event listbox.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -