0

I have a Tkinter app that contains a menu. I can add cascades and commands in these cascades but can I add a command to the original app menu? The one that is created automatically on macOS and gets the name of the app:

enter image description here

Here is my code:

from tkinter import *

root = Tk()

menubar = Menu(root)

# I can create a cascade
cascade1 = Menu(menubar, tearoff=0)
menubar.add_cascade(label="Cascade 1", menu=cascade1)
# And add a command to this cascade
cascade1.add_command(label="Command 1")

# How to add a command to the "Python" menu
# ???

root.config(menu=menubar)

root.mainloop()

1 Answer 1

1

I don't think it's possible to add a command anywhere on that menu except at the very top. However, you can add items at the top by creating a menu with the name "apple". Items you add to that menu will appear at the top of the application menu.

Note: you must configure this menu before assigning the menubar to the root window.

import tkinter as tk

root = tk.Tk()
menubar = tk.Menu(root)

appmenu = tk.Menu(menubar, name='apple')
menubar.add_cascade(menu=appmenu)
appmenu.add_command(label='My Custom Command')
appmenu.add_separator()

root.configure(menu=menubar)

root.mainloop()

screenshot of menu

For reference, see Special menus in menubars in the the tcl/tk documentation.

Sign up to request clarification or add additional context in comments.

1 Comment

Exactly what I was looking for, thank you. I will take a look to this documentation for more information.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.