[Pythonmac-SIG] Question about Tkinter listbox
Josh English
english@spiritone.com
30 May 2001 21:27:51 -0700
I am new to python and I am using MacPython 2.1 and Tk 8.9 on Mac OS
9.0. I am having difficulty figuring out how to get the selected item in
a listbox into an entry data field. I have tried the following code
after lots of failed experiments:
from Tkinter import *
names = ['Josh','Steph']
class window(Frame):
def sendname(self):
index = namelist.curselection() # Fails here
print index # for testing
label = namelist.get(index) # Fails here
print label # for testing
root=Tk()
namelist = Listbox(root)
pos = 0
for name in names:
namelist.insert(pos,name)
pos=pos+1
namelist.pack(side=LEFT,fill=Y)
namelist.bind('<Double-1>',sendname)
nameentry = Entry(root)
nameentry.pack(side=TOP,fil=X)
window().mainloop()
In Programming Python by Mark Lutz there is a ScrolledList class on
page 372 and I've adapted the code for this. I'm ignoring the scroll bar
and focusing on just this one issue. I want to get the nameentry field
to reflect what is selected in namelist.
Any suggestions?
Josh English
english@spiritone.com