Tkinter listbox selection handling
Martin Franklin
mfranklin1 at gatwick.westerngeco.slb.com
Mon Nov 11 17:12:49 EST 2002
On Mon, 2002-11-11 at 19:00, Tim Daneliuk wrote:
> Martin Franklin wrote:
> > Try this...
> >
> > UI.listbox.bind("<ButtonRelease-1>", handlerfunc)
>
>
> I had tried this as well - same problem. The use of listbox.nearest(event.y)
> suggested here seemed to work best.
>
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.
More information about the Python-list
mailing list