Reputation: 1
Why does the following test not display the menu on my Mac running Python 3.7 on Mojave?
Tried a shebang but that didn't help.
import tkinter as tk
def quit_app():
my_window.destroy()
my_window = tk.Tk()
my_menu = tk.Menu(my_window)
my_menu.add_command(label='Quit',command=quit_app)
my_window.config(menu=my_menu)
my_window.mainloop()
The menu displays in Windows 10 but not on the Mac. The tkinter window is blank on the Mac.
Upvotes: 0
Views: 664
Reputation: 805
The menu displays in Windows 10 but not on the Mac
Yes, that is because MAC has a design philosophy that all devs for their platform have to conform with.
You cannot have a add_command
as a top level menu item on mac, rather:
import tkinter as tk
def quit_app():
my_window.destroy()
my_window = tk.Tk()
my_menu = tk.Menu(my_window)
quit_menu= tk.Menu(my_menu, tearoff=0)
quit_menu.add_command(label='Quit App',command=quit_app)
my_menu.add_cascade(label="Quit", menu=quit_menu, underline=0)
my_window.config(menu=my_menu)
my_window.mainloop()
Upvotes: 1