2016-09-26 318 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