I was trying to make the currently selected Listbox
item to be printed out. For example, when I select item "one", it should print out "one" and when I select item "two", it should print out "two" etc. The following is what I have tried.
from Tkinter import*
root=Tk()
sizex = 600
sizey = 400
posx = 40
posy = 20
root.wm_geometry("%dx%d+%d+%d" % (sizex, sizey, posx, posy))
itemsforlistbox=['one','two','three','four','five','six','seven']
def CurSelet(evt):
value=str((mylistbox.get(ACTIVE)))
print value
mylistbox=Listbox(root,width=60,height=10,font=('times',13))
mylistbox.bind('<<ListboxSelect>>',CurSelet)
mylistbox.place(x=32,y=90)
for items in itemsforlistbox:
mylistbox.insert(END,items)
root.mainloop()
My problem is whenever I selected an item in the listbox, it is actually printing out the previously selected item.For example, the moment I select the item "two" in the list, it is printing out "one". To make things more clear,please see the following
- I selected the item "one", it printed out "one"
- I selected the item "two", it print out "one" again
- I selected the item "three", it print out "two" and so on...
Am I missing something? or did I misunderstand the way the get(ACTIVE)
works?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…