Tkinter listbox selection handling

ID5 id5id5 at seed.net.tw
Sun Nov 10 09:17:35 EST 2002


Tim Daneliuk <tundra at tundraware.com> wrote in message news:<co6kqa.tqk2.ln at boundary.tundraware.com>...
> Then I add a handler:
> 
> UI.listbox.bind('<button-1>', handlerfunc)
> 
> All this works fine up to a point.  However, inside handlerfunc(), if I do
> a UI.listbox.selection_get(,) I get the *previously* selected item back,
> not the currently selected item.  This is also the case if I try using
> UI.listbox.curselection().
> 
> I've worked around this by trashing the idea of an event handler and
> polling the widget regularly looking for changes, but that is a really
> ugly solution... This was suggested in some of my reading because there
> is no 'command' attribute for a Listbox.
> 
> So, am I missing something here? *Is* there a way to use events to
> pickup the currently selected Listbox item, or am I stuck doing it with
> polling?

Try this:

def handlerfunc(Index):
        NewIndex = UI.listbox.nearest(Index.y)
        print UI.listbox.get(NewIndex)

ID5~~



More information about the Python-list mailing list