0
我對這個小部件很困惑,有人可以修復它嗎?Tkinter menubutton錯誤
from Tkinter import *
master = Tk()
mytext = StringVar()
mytext.set("DEFAULT")
def test_function(evt):
mb.menu.delete(0, END)
for i in range(20):
mb.menu.add("command", label='%s'%i, command= lambda : mytext.set("%s"%i))
mb= Menubutton (master, text="Test", relief=RAISED)
mb.menu = Menu (mb, tearoff = 0)
mb["menu"] = mb.menu
mb.bind('<Button-1>', test_function)
mb.grid(row = 0, column=1)
Label(master, textvariable=mytext).grid(row = 0, column=0)
master.mainloop()
mytext
總是顯示列表的末尾,當選中按鈕時如何解決它?
非常感謝你的代碼是作品:d – user3745488