Reputation: 8978
I keep getting the error:
_tkinter.TclError: unknown option "-menu"
My MWE looks like:
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()
I'm on OS X 10.8 using python 3. Why am I getting the unknown option error?
Upvotes: 0
Views: 13899
Reputation: 76194
self.config(menu=self.menuBar)
menu
is not a valid configuration option for Frame
.
Perhaps you meant to inherit from Tk
instead?
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()
Upvotes: 6