Tkinter listbox selection handling
Tim Daneliuk
tundra at tundraware.com
Mon Nov 11 19:20:07 EST 2002
Martin Franklin wrote:
<SNIP>
> There must be something else in the code your not showing (the code you
> posted did not work out of the bx...) This works:-
>
> #### start
>
> from Tkinter import *
>
> class myUI:
> def __init__(self, root):
> self.listbox = Listbox(root,
> selectmode=SINGLE,
> exportselection=0)
> self.listbox.pack()
> root = Tk()
> UI = myUI(root)
>
>
> def handlerfunc(event):
> print event.widget.get(first=event.widget.curselection()[0])
>
> UI.listbox.insert("end", "1")
> UI.listbox.insert("end", "2")
> UI.listbox.insert("end", "3")
> UI.listbox.insert("end", "4")
>
>
> UI.listbox.bind('<ButtonRelease-1>', handlerfunc)
>
> root.mainloop()
>
> #### end
>
>
> Tested just a few seconds ago on a RedHat Linux 8.0 Python 2.2.2
> Tk 8.4 and Python 2.2.2 Tk 8.3
>
>
> Cheers,
> Martin.
I must have had some other artifacts that were breaking things when I
tried <ButtonRelease-1> previously. It now works fine, exactly as you
suggest...
Thanks, all, for taking the time to help ...
--
------------------------------------------------------------------------------
Tim Daneliuk
tundra at tundraware.com
More information about the Python-list
mailing list