我正在尝试使用tkinter. 我正在使用 Mac OS Big Sur,我在tkinter menus.
将菜单项添加到默认的 mac 菜单栏是没有问题的,但我想删除一些无用的。我看到您可以使用此命令自定义“首选项”项。
root.createcommand('tk::mac::ShowPreferences', showMyPreferencesDialog)
但我找不到其他任何东西。这可能吗?
可悲的是,我没有足够的声誉来发表评论。回答您的子问题:您可以通过按Cmd+Shift+3全屏或Cmd+Shift+4矩形选择来进行屏幕截图。如果这不起作用,您必须检查您的System Preferences > Keyboard > Shortcuts > Screenshots设置。
关于您的菜单问题,您可以随时更换整个菜单。这是一个教程。但请注意,第一个菜单将始终保持不变,因为它不属于应用程序,而是属于系统。
这是教程的副本:
from Tkinter import *
def donothing():
filewin = Toplevel(root)
button = Button(filewin, text="Do nothing button")
button.pack()
root = Tk()
menubar = Menu(root)
filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label="New", command=donothing)
filemenu.add_command(label="Open", command=donothing)
filemenu.add_command(label="Save", command=donothing)
filemenu.add_command(label="Save as...", command=donothing)
filemenu.add_command(label="Close", command=donothing)
filemenu.add_separator()
filemenu.add_command(label="Exit", command=root.quit)
menubar.add_cascade(label="File", menu=filemenu)
editmenu = Menu(menubar, tearoff=0)
editmenu.add_command(label="Undo", command=donothing)
editmenu.add_separator()
editmenu.add_command(label="Cut", command=donothing)
editmenu.add_command(label="Copy", command=donothing)
editmenu.add_command(label="Paste", command=donothing)
editmenu.add_command(label="Delete", command=donothing)
editmenu.add_command(label="Select All", command=donothing)
menubar.add_cascade(label="Edit", menu=editmenu)
helpmenu = Menu(menubar, tearoff=0)
helpmenu.add_command(label="Help Index", command=donothing)
helpmenu.add_command(label="About...", command=donothing)
menubar.add_cascade(label="Help", menu=helpmenu)
root.config(menu=menubar)
root.mainloop()