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