Reputation: 755
I've come across what I think may be a bug where whenever I try to make a menubar (Menu
) in tkinter on mac, any non-cascade type menu items -- that is, menu.add_command
instead of menu.add_cascade
-- do not appear to work.
import tkinter as tk
def callback():
print("Hello World")
root = tk.Tk()
menu = tk.Menu(root)
# Adding cascade
menu2 = tk.Menu(menu, tearoff=0)
menu2.add_command(label="CascadeItem", command=callback)
menu.add_cascade(menu=menu2, label="Cascade")
# Adding non-cascade
menu.add_command(label="NonCascade", command=callback)
root.config(menu=menu)
root.mainloop()
When I run the preceding code, I am able to see the "Cascade" menu item, but not the "NonCascade" menu item.
Is there something I am doing wrong here? Is this some type of bug? Or does mac not support non-cascade type menu items on menubars?
Upvotes: 0
Views: 851
Reputation: 385970
You are correct: you cannot add commands to the menubar on OSX. There is no workaround. From a usability point of view this is a bad idea, so OSX prohibits it.
Upvotes: 2