0
这是一个给我麻烦的应用程序部分:当我点击'select category'时,当'Cheese'被选中时它应该输出1,但它总是输出0。告诉我为什么,并给我一个修复?我知道我应该把它作为一个对象来组织,但是我想把'categories'作为Tkinter主对象的一个属性。我是python和Tkinter的新手,不知道如何访问属性。谢谢。Tkinter不会更新列表框选择
import Tkinter
root = Tkinter.Tk()
root.title('Test App')
mainFrame = Tkinter.Frame(root)
def mainWindow():
categories = [['Bread','Rye','Wheat'],['Cheese','Feta']]
categoryListbox = Tkinter.Listbox()
for category in categories:
categoryListbox.insert('end', category[0])
categoryListbox.pack()
activeIndex = categoryListbox.index('active')
selectCategoryButton = Tkinter.Button(text="Select Category", command= lambda: selectCategory(activeIndex))
selectCategoryButton.pack()
def selectCategory(activeIndex):
print activeIndex
root.mainloop()
很酷,谢谢。那样做了。 – LMNOP