Home > Blockchain >  tkinter menu not showing (Mac) in the tkinter app
tkinter menu not showing (Mac) in the tkinter app

Time:03-09

I try to create a menu with tkinter and python. I am using latest Python and I am on latest Mac OS Monterey.

import tkinter as tk

class MainApp(tk.Frame):
    def __init__(self, parent, *args, **kwargs):
        tk.Frame.__init__(self, parent, *args, **kwargs) 
        self.parent = parent   

        my_menu = tk.Menu(self.parent)
        self.parent.config(menu=my_menu)
        
        app_menu = tk.Menu(my_menu)
        my_menu.add_cascade(label="Options", menu=app_menu)
        app_menu.add_separator()
        app_menu.add_command(label="Exit", command=self.confirm_exit)
        
        self.label = tk.Label(self.parent, text="testing", pady=10, borderwidth=1) 
        self.label.pack(fill='both')
        
    def confirm_exit(self):
            self.parent.destroy()


def main():
    root = tk.Tk()
    app = MainApp(root)
    app.pack()
    root.mainloop()
       
if __name__ == "__main__":
    main()

The menu shows at the top of the screen as a native menubar on Mac. Is there any way you can add the menubar to the tkinter app itself on Mac?

CodePudding user response:

The menu shows at the top of the screen as a native menubar on Mac. Is there any way you can add the menubar to the tkinter app itself on Mac?

No, there is not, unless you use XQuartz and an X11 build of tkinter. Menus and menubars are designed to be native on OSX and Windows.

You can simulate a menubar by using a Frame and some Menubutton widgets. However, you'll still have the menu at the top.

  • Related