我还是复制了这段代码
from Tkinter import * import tkMessageBox import Tkinter
top = Tk()
mb= Menubutton ( top, text="condiments", relief=RAISED ) mb.grid() mb.menu = Menu ( mb, tearoff = 0 ) mb["menu"] = mb.menu
mayoVar = IntVar() ketchVar = IntVar()
mb.menu.add_checkbutton ( label="mayo", variable=mayoVar ) mb.menu.add_checkbutton ( label="ketchup", variable=ketchVar )
mb.pack() top.mainloop()
当某人单击mayo ..我希望它执行特定功能
答案 0 :(得分:1)
使用回调函数来实现所需的操作,然后从菜单项中调用它:
def callback_function():
# Your code here
mb.menu.add_checkbutton(label="mayo", variable=mayoVar,
command=callback_function)