[Tkinter-discuss] How to Handle Selected Item Event of ListBox
Michael Lange
klappnase at web.de
Thu Mar 3 22:44:12 CET 2011
Hi Behseini ,
Thus spoketh Behseini <suffii at gmail.com>
unto us on Wed, 2 Mar 2011 17:23:59 -0800 (PST):
(...)
>
> can you please take a look at this code and let me know how I can call
> one of the method by selecting the item from the list?
You will want to have a look at the Listbox widget's <<ListboxSelect>>'
virtual event, which is generated each time the selection changes (see
the listbox Tk man page for details). A brief usage example:
#########################################
from Tkinter import *
root = Tk()
l = Listbox(root, selectmode='multiple')
l.pack()
def on_select(event):
print event.widget.curselection()
l.bind('<<ListboxSelect>>', on_select)
for i in range(10):
l.insert('end', 'Item %d' % i)
root.mainloop()
#########################################
I hope this helps
Michael
.-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-.
No one may kill a man. Not for any purpose. It cannot be condoned.
-- Kirk, "Spock's Brain", stardate 5431.6
More information about the Tkinter-discuss
mailing list