How to make Menu.add_command () work in tkinter on Mac?

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

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

On OS X 10.10.1 (Yosemite), buttons are not displayed. I know that I can create a drop-down menu with red and blue commands, but in my real application, I would prefer not to.

 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?

+5
source share
1 answer

I don’t think you can do this with your native (β€œAqua”) Tk on OS X, and you probably shouldn't try. OS X's external menus do not work this way, and Tk is trying to follow the Apple User Interface Guide for the menu . You need to have a menu bar with drop-down cascades.

The TkDocs website has a good understanding of the Tk menus and their platform differences. (You can use Tk on X11 in OS X, but this is not recommended since Apple no longer sends X11 servers with OS X, and your application will look weird and behave weird for OS X users.)

+5
source

Source: https://habr.com/ru/post/1210936/


All Articles