How to listen the Tkinter application "About" button action on MAC

Viewed 91

I am developing a Desktop application by Python tkinter library. I didn't write code for menu bar in the application by default it's creating on Mac. I want to listen the action, I can listen the Quit button

app.createcommand("::tk::mac::Quit", on_closing) 

I don't know how to listen the About button action. I have tried with ::tk::mac::About and ::tk::mac::standardAboutPanel. Can you suggest what to use to listen the About button on mac.

Note: It's default menu created by mac. So, just we need to listen the action that's it. If we listen we can call the method for the about.enter image description here

1 Answers

You can't explicitly listen for activation of the default "About" menu. You can, however, create your own "About" menu.

There are two important steps. First, the internal name of the menu needs to be "about", and this menu needs to be added to the menubar before you add the menubar to the root window.

If you follow those two rules, any menu items you create will be placed before the default menu items. Here's a simple example:

import tkinter as tk

root = tk.Tk()

def show_about():
    top = tk.Toplevel()
    label = tk.Label(top, text="This is my custom 'about' window")
    button = tk.Button(top, text="Ok", command=top.destroy)
    button.pack(side="bottom", pady=20)
    label.pack(padx=20, pady=20)

menubar = tk.Menu(root)
apple_menu = tk.Menu(menubar, name="apple")
menubar.add_cascade(menu=apple_menu)
apple_menu.add_command(label="About mediavalet", command=show_about)
root.configure(menu=menubar)

root.mainloop()

screenshot of menu

A good reference for platform-specific menus is the Menu tutorial on tkdocs.com

Related