以下是生成带有一个标签“做某事”的 Tkinter 菜单。运行脚本会立即产生“完成”输出,这意味着甚至在单击“做某事”菜单标签之前。这是为什么?我对@staticmethod 做错了吗?感谢期待。
import Tkinter
class AppMenu(object):
def __init__(self, master):
self.master = master
self.file_content = "initialised"
self.menu_bar(self.file_content)
def menu_bar(self, file_content):
menu_bar = Tkinter.Menu(self.master)
self.menu_bar = Tkinter.Menu(self.master)
self.master.config(menu=self.menu_bar)
self.task_menu = Tkinter.Menu(self.menu_bar, tearoff = False)
self.task_menu.add_command(label = "do something", command = Convert.do(self.file_content))
self.menu_bar.add_cascade(label = "Task", menu = self.task_menu)
class Convert(object):
@staticmethod
def do(text):
print "done"
root = Tkinter.Tk()
Menu = AppMenu(root)
root.mainloop()