[英]Tkinter error: _tkinter.TclError: unknown option "-menu"
[英]Tkinter Unknown Option -menu
我不断收到错误:
_tkinter.TclError:未知选项“ -menu”
我的MWE看起来像:
from tkinter import *
def hello():
print("hello!")
class Application(Frame):
def createWidgets(self):
self.menuBar = Menu(master=self)
self.filemenu = Menu(self.menuBar, tearoff=0)
self.filemenu.add_command(label="Hello!", command=hello)
self.filemenu.add_command(label="Quit!", command=self.quit)
def __init__(self, master):
Frame.__init__(self, master)
self.pack()
self.createWidgets()
self.config(menu=self.menuBar)
if __name__ == "__main__":
root = Tk()
ui = Application(root)
ui.mainloop()
我在使用python 3的OS X 10.8上。为什么会出现未知选项错误?
self.config(menu=self.menuBar)
menu
不是Frame
的有效配置选项。
也许您是想从Tk
继承?
from tkinter import *
def hello():
print("hello!")
class Application(Tk):
def createWidgets(self):
self.menuBar = Menu(master=self)
self.filemenu = Menu(self.menuBar, tearoff=0)
self.filemenu.add_command(label="Hello!", command=hello)
self.filemenu.add_command(label="Quit!", command=self.quit)
self.menuBar.add_cascade(label="File", menu=self.filemenu)
def __init__(self):
Tk.__init__(self)
self.createWidgets()
self.config(menu=self.menuBar)
if __name__ == "__main__":
ui = Application()
ui.mainloop()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.