简体   繁体   English

Tkinter 菜单栏不显示在 Mac OS 上

[英]Tkinter Menubars doesn't show up on Mac OS

I would like to create a menubar on mac os with tkinter.我想用 tkinter 在 mac os 上创建一个菜单栏。 My program runs, but nothing appears on the menubar.我的程序运行,但菜单栏上没有任何内容。 I can only see the Python menubar, nothing else is shown.我只能看到 Python 菜单栏,没有显示其他内容。 My custom menus don't even show up on the mac menubar.我的自定义菜单甚至没有出现在 mac 菜单栏上。 As far as I know it should be visible there.据我所知,它应该在那里可见。 I would appreciate some help.我会很感激一些帮助。 Here is my code:这是我的代码:

from tkinter import *

def openFile():
    print("File has been opened!")
def saveFile():
    print("File has been saved!")
def cut():
    print("You cut some text!")
def copy():
    print("You copied some text!")
def paste():
    print("You pasted some text!")

window = Tk()

menubar = Menu(window)

fileMenu = Menu(menubar,tearoff=0,font=("MV Boli",15))
menubar.add_cascade(label="File",menu=fileMenu)
fileMenu.add_command(label="Open",command=openFile)
fileMenu.add_command(label="Save",command=saveFile)
fileMenu.add_separator()
fileMenu.add_command(label="Exit",command=quit)

editMenu = Menu(menubar,tearoff=0,font=("MV Boli",15))
menubar.add_cascade(label="Edit",menu=editMenu)
editMenu.add_command(label="Cut",command=cut)
editMenu.add_command(label="Copy",command=copy)
editMenu.add_command(label="Save",command=paste)

window.mainloop()

To create a menubar for a window, first, create a menu widget.要为窗口创建菜单栏,首先,创建一个菜单小部件。 Then, use the window's menu configuration option to attach the menu widget to the window.然后,使用窗口的菜单配置选项将菜单小部件附加到窗口。

menubar = Menu(window)
window['menu'] = menubar

There are still nuances for Mac OS, read Menus Mac OS 仍有细微差别,请阅读菜单

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM