2016-09-26 314 views
-2

我学习Python的Tkinter的,但我有一个错误,每当我试图编译:如何解决“_tkinter.TclError:未知选项”?

Traceback (most recent call last): 
File "<stdin>", line 1, in <module> 
File "/usr/lib/python2.7/dist-packages/spyderlib/ 
widgets/externalshell/sitecustomize.py", line 540, in runfile 
execfile(filename, namespace) 
File "/home/jason/.spyder2/.temp.py", line 14, in <module> 
menu.config(menu=menu) 
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1274, 
inconfigure 
return self._configure('configure', cnf, kw) 
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1265, 
in _configure 
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf)) 
_tkinter.TclError: unknown option "-menu"). 

我的代码是:

from tkinter import * 

def hello(): 
    print "hello"  

root = Tk() 
menu = Menu(root) 
menu.config(menu=menu) 
menu.add_command(label ="new",command = hello) 

root.mainloop() 

回答

0

你必须与你的代码一点点的问题。而不是menu.config,使用root.config,你不会得到任何这样的错误。

欲了解更多信息和详细的教程,请访问Tkinter Menu Widget