[Tkinter-discuss] How to Handle Selected Item Event of ListBox

Michael Lange klappnase at web.de
Fri Mar 4 10:41:31 CET 2011


Hi,

Thus spoketh Behseini <suffii at gmail.com> 
unto us on Thu, 3 Mar 2011 15:22:06 -0800 (PST):

> 
> Thanks Michael
> But in this issue I have to have a if clause to select from the user
> chose some thing  like
>   self.zones = self.Lb1.curselection()
>     if self.zones == 1:
>         command=self.make_Red()
>     if self.zones == 2:
>         command=self.make_Red()
>     if self.zones == 3:
>         command=self.make_Red()
> 
> But i can/t figure it out how to set it up
> Thanks for your time again
> 

sorry, i thought this was obvious ;) You simply need to change the
ListboxSelect callback from my example into something like:


 def on_select(event):
    sel = event.widget.curselection()
    if sel[0] == 1:
        do_this()
    elif sel[0] == 2:
        do_that()
    ....

I hope this helps

Michael



.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Compassion -- that's the one things no machine ever had.  Maybe it's
the one thing that keeps men ahead of them.
		-- McCoy, "The Ultimate Computer", stardate 4731.3


More information about the Tkinter-discuss mailing list