Tkinter Unknown Option -menu
I keep getting the error: _tkinter.TclError: unknown option '-menu' My MWE looks like: from tkinter import * def hello(): print('hello!') class Application(Frame):
Solution 1:
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 *
defhello():
print("hello!")
classApplication(Tk):
defcreateWidgets(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()
Post a Comment for "Tkinter Unknown Option -menu"