PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, November 8, 2022

[FIXED] How to customize tkinter menubar on mac?

 November 08, 2022     macos, menu, python, tkinter     No comments   

Issue

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?


Solution

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()


Answered By - lupdidup
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing