PucciLaCanton
PucciLaCanton

Reputation: 83

How to customize tkinter menubar on mac?

I am trying to build an application with tkinter. I am using Mac OS Big Sur and I struggle a little bit with tkinter menus.

enter image description here (How do you do screenshots when you want to see the open menubar Haha)

It is no problem to add menu items to that default mac menubar but I want to delete some useless ones. I saw that you can customize the "Preferences" item with this command. root.createcommand('tk::mac::ShowPreferences', showMyPreferencesDialog) But I could not find anything else. Is this possible?

Upvotes: 2

Views: 2861

Answers (1)

lupdidup
lupdidup

Reputation: 311

Sadly, I don't have enough reputation to place a comment. Answering your subquestion: you can do screenshots by pressing Cmd+Shift+3 for fullscreen, or Cmd+Shift+4 for a rectangular selection. If that does not work, you have to check your System Preferences > Keyboard > Shortcuts > Screenshots setting.

Regarding your menu question, you can always replace the whole menu. Here is a tutorial. Though note, the first menu will always stay the same because it does not belong to the app but the system.

Here is a copy of the 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()

Upvotes: 2

Related Questions