Menu item in Tkinter is not working properly (in MacOS)

658 Views Asked by At

I am making a tkinter app with multiple pages. The simple version of the codes I used is shown below. I added the menu to the root of the app and gave one option of File with sub-option of "Reload Defaults" and "Exit".

When I run this code then I do get the menu but not on the GUI but the main menu bar of Mac. And the menu is unresponsive. I am not sure what I am doing wrong!

import tkinter as tk
from tkinter import ttk
from tkinter import RAISED


LARGEFONT =("Verdana", 35)

class tkinterApp(tk.Tk):

    # __init__ function for class tkinterApp
    def __init__(self, *args, **kwargs):

        # __init__ function for class Tk
        tk.Tk.__init__(self, *args, **kwargs)

        # creating a container
        container = tk.Frame(self)
        container.pack(side = "top", fill = "both", expand = True)

        container.grid_rowconfigure(0, weight = 1)
        container.grid_columnconfigure(0, weight = 1)

        container2 = tk.Frame(self, relief=RAISED, borderwidth=2)
        container2.pack(side="bottom",fill="both", expand=True)
        container2.grid_rowconfigure(0, weight = 1)
        container2.grid_columnconfigure(0, weight = 1)

        def runProg():
            print("response from runProg")
            #get all entry value from page 2


        runButton = ttk.Button(container2, text="Run", command=runProg)
        runButton.pack(side="left", padx=5, pady=5)

        ######################################################
        ## Menu items
        progMenu = tk.Menu(self,tearoff=0)
        self.config(menu=progMenu)

        #create File menu
        def reload_command():
            pass

        fileMenu = tk.Menu(progMenu)
        progMenu.add_cascade(label="File", menu=fileMenu)
        fileMenu.add_command(label="Reload Defaults", command=reload_command)
        fileMenu.add_command(label="Exit", command=reload_command)
        ######################################################

        # initializing frames to an empty array
        self.frames = {}
        frame = StartPage(container, self)

        self.frames[StartPage] = frame

        frame.grid(row = 0, column = 0, sticky ="nsew")

        self.show_frame(StartPage)

    # to display the current frame passed as
    # parameter
    def show_frame(self, cont):
        frame = self.frames[cont]
        frame.tkraise()

# first window frame startpage

class StartPage(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)

        # label of frame Layout 2
        label = ttk.Label(self, text ="Startpage", font = LARGEFONT)

        # putting the grid in its place by using
        # grid
        label.grid(row = 0, column = 2, padx = 10, pady = 10)


app = tkinterApp()
app.mainloop()

Any help would be greatly appreciated!

enter image description here

1

There are 1 best solutions below

2
On

You might want to change the menu to be buttons at the top of the grid as on a Mac you will get this bug, but on windows it works perfectly fine. enter image description here