我正在尝试用tkinter
构建一个应用程序。我使用的是Mac Sur,使用tkinter
menus
有点困难。
(当你想看到打开的菜单栏时,你该如何截图哈哈)
向默认mac菜单栏添加菜单项没有问题,但我想删除一些无用的菜单项。我看到您可以使用此命令自定义"Preferences“项。root.createcommand('tk::mac::ShowPreferences', showMyPreferencesDialog)
,但我找不到其他任何东西。这个是可能的吗?
发布于 2021-07-20 20:21:32
遗憾的是,我没有足够的名气来发表评论。回答你的子问题:你可以通过按Cmd+Shift+3
进行屏幕截图,或者按Cmd+Shift+4
进行矩形选择。如果这不起作用,你必须检查你的System Preferences > Keyboard > Shortcuts > Screenshots
设置。
关于你的菜单问题,你可以随时替换整个菜单。这是a tutorial。请注意,第一个菜单将始终保持不变,因为它不属于应用程序,而属于系统。
以下是本教程的副本:
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()
https://stackoverflow.com/questions/68331195
复制相似问题