I'm having an error while creating a menu in Python using Tkinter. What am I doing wrong? My code and complete error traceback are given below.
My code:
from tkinter import *
root = Tk()
root.title("FoodU")
root.geometry("1600x2560+0+0")
#main BEGIN
main = Frame(root, bg="light coral")
main.pack(fill=BOTH)
#main END
#navigation BEGIN
navigation = Frame(main, bg="floral white")
navigation.grid(padx=20)
nav = Menu(navigation)
navigation.config(menu=nav)
navcuisine = Menu(nav)
nav.add_casacde(label="Cuisines", menu=navcuisine)
navcuisine.add_command(label="Indian")
navcuisine.add_command(label="Chinese")
navcuisine.add_command(label="Japanese")
navcuisine.add_command(label="Italian")
navcuisine.add_command(label="Thai")
#navigation END
root.mainloop()
The error:
Traceback (most recent call last):
File <file path>, line 52, in <module>
navigation.config(menu=nav)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/tkinter/__init__.py", line 1482, in configure
return self._configure('configure', cnf, kw)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/tkinter/__init__.py", line 1473, in _configure
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: unknown option "-menu"
What does this error mean? What am I doing wrong, and how can I fix it?
Thank you so much!!
navigation = Frame(main, bg="floral white")
navigation.grid(padx=20)
nav = Menu(navigation)
navigation.config(menu=nav)
This is a problem. Frame objects do not support the menu
configuration option. As far as I know, only Toplevel widgets allow menu
. One possible solution is to make nav
a menu of root
instead.
nav = Menu(root)
root.config(menu=nav)
Additionally, nav.add_casacde(label="Cuisines", menu=navcuisine)
misspells "cascade". Try nav.add_cascade(label="Cuisines", menu=navcuisine)
instead.