7

If I create a tkinter menu on OS X and try to add a menu button to it with add_comand(), nothing shows up in the menu.

If the code below is run on Ubuntu, I get a menubar with two commands labeled "Red" and "Blue" that change the background color of the window.

On OS X 10.10.1 (Yosemite) the buttons do not appear. I know I can make a dropdown menu with the Red and Blue commands, but in my real app, I'd prefer not to do that.

from platform import python_version_tuple

major = python_version_tuple()[0]

if major == '3':
    import tkinter as tk
else:
    import Tkinter as tk

root = tk.Tk()

fr = tk.Frame(root, height = 200, width = 200)
fr.pack()
menu = tk.Menu(root)
root.configure(menu=menu)
menu.add_command(label='Red', command=lambda:fr.configure(bg='red'))
menu.add_command(label='Blue', command=lambda:fr.configure(bg='blue'))

root.mainloop()

Can you tell me how to do what I want?

nbro
  • 15,395
  • 32
  • 113
  • 196
saulspatz
  • 5,011
  • 5
  • 36
  • 47
  • 1
    While some systems will allow you to do this, it leads to very poor usability for your app unless you're very careful to make it clear which items are menus and when are buttons. It's best to only have dropdown menus on your menubar. – Bryan Oakley Jan 12 '15 at 22:21

1 Answers1

7

I don't think you can do that with the native ("Aqua") Tk on OS X and you probably shouldn't try. OS X native menus don't work like that and Tk tries to follow Apple's Human Interface Guide for menus. You need to have a menu bar with dropdown cascades.

The TkDocs website has a good introduction to Tk menus and their platform differences. (You could use an X11-based Tk on OS X, but that is not recommended as Apple does not ship X11 servers anymore with OS X and your app would look and behave oddly for OS X users.)

nbro
  • 15,395
  • 32
  • 113
  • 196
Ned Deily
  • 83,389
  • 16
  • 128
  • 151