如果我在OS X上创建一个tkinter菜单并尝试向其添加菜单按钮,则菜单中add_comand()不会显示任何内容.
如果下面的代码在Ubuntu上运行,我会得到一个带有两个标记为"红色"和"蓝色"的命令的菜单栏,它们会改变窗口的背景颜色.
在OS X 10.10.1(Yosemite)上,按钮不会出现.我知道我可以使用红色和蓝色命令制作一个下拉菜单,但在我的真实应用程序中,我宁愿不这样做.
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()
Run Code Online (Sandbox Code Playgroud)
你能告诉我怎么做我想要的吗?