0

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.

ram_23
  • 79
  • 11
TamP
  • 1
  • 2
  • 1
    Have you read e.g. https://stackoverflow.com/q/52529403/3001761? – jonrsharpe Sep 10 '19 at 09:46
  • Hi there, welcome to Stack Overflow. Please read through the "How to ask a good question" section before asking a question. https://stackoverflow.com/help/how-to-ask Please consider giving a better title/question heading. Also please be careful of duplicating questions, search for similar questions before asking one yourself. – Roan Sep 10 '19 at 09:59

1 Answers1

1

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()
Samuel Kazeem
  • 787
  • 1
  • 8
  • 15