Events and the Listbox widget

Dan Kuchler kuchler at ajubasolutions.com
Tue Oct 3 04:30:13 EDT 2000


Hans Kristian Ruud wrote:
> 
> I have generated a listbox, and wish to extract some information when a
> user
>   clicks on an item:
> 
>           list = Listbox(canvas,width=15 )
>           list.pack(side=TOP)
>           list.bind('<ButtonPress>', chooseSheet)
> 
>           def chooseSheet(event):
>                   listbox = event.widget
>                   selected = listbox.curselection()
>                   setCurSheet( selected[0] )
> 
>   My problem is that the list of selected values from
> listbox.curselection()
>   is not updated until after chooseSheet is called, i.e. the function
> 
>   listbox.curselection()
> 
>   returns the PREVIOUS element that was clicked.
> 
>   Originally I had bound the function to root, and then it worked fine,
> however
>   I do not want the function chooseSheet to be executed when I click on
> buttons
>   and such that I have added later.
> 

The problem is the order in which the bindings are getting called.
The binding that causes selection to change isn't getting called
until after your binding is getting called.

This exact same question was answered in comp.lang.tcl
just last week.  Read Eric Melski's response at:

http://x63.deja.com/viewthread.xp?AN=674921495

I hope that helps explain what is going on.

--Dan



More information about the Python-list mailing list