【发布时间】:2016-03-04 05:19:20
【问题描述】:
我有这个 python 代码:
def initUI(self):
self.parent.title("Simple menu")
menubar = Menu(self.parent)
self.parent.config(menu=menubar)
#file menu
fileMenu = Menu(menubar)
menubar.add_cascade(label="File", menu=fileMenu)
fileMenu.add_command(label="Exit", command=self.quit, accelerator="Ctrl+Q")
self.bind_all("<Control-q>", self.quit)
def quit(self):
sys.exit(0)
当我从菜单中选择退出时,它工作正常。但是,当我按ctrl+q 时,我收到此错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tkinter/__init__.py", line 1538, in __call__
return self.func(*args)
TypeError: quit() takes 1 positional argument but 2 were given
这到底是怎么回事?
【问题讨论】:
-
通过查看你的代码我可以说一件事,函数 quit(self) 的缩进不正确。我确定如果你尝试运行这个模块,它会抛出语法错误。
-
抱歉,在课堂上。
标签: python-3.x tkinter