When creating a menu in Python 3.6 and tkinter, drop down doesnt stay in Frame

Question:

Edit: OS is Windows 10 64 Bit

Ok, so I have googled my rear-end off on this one. I am building a simple tkinter app and upon setting it up and just generally messing around with options to add to it, my drop down from the menu created doesn’t stay constrained inside the Frame.

import tkinter as tk


class Window(tk.Frame):

    def __init__(self, master=None):
        super().__init__(master)
        self.master = master
        self.main_window()
        self.widgets()

    # All main window parameters go here
    def main_window(self):
        self.master.title("Calculate Commission")
        self.master.geometry("800x600")
        self.pack()

    def widgets(self):
        main_menu = tk.Menu(self.master, tearoff=0)
        self.master.config(menu=main_menu)

        # Create File Menu and Drop Down
        file = tk.Menu(main_menu, tearoff=0)
        file.add_command(label="Save")
        file.add_command(label="Exit", command=exit)
        main_menu.add_cascade(label="File", menu=file)

        # Create Edit Menu and Drop Down
        edit = tk.Menu(main_menu, tearoff=0)
        edit.add_command(label="undo")
        main_menu.add_cascade(label="Edit", menu=edit)


main = tk.Tk()
comm_prog = Window(master=main)
main.mainloop()

Please see this attached screenshot to see what I am referring too: Menu Outisde of Frame

I am fairly confident this may end up either of two ways. Either it’s a rookie mistake I am making somewhere, or its system dependent and its just specific to my computer for some reason. If anyone has any insight, I would greatly appreciate it.

Adding screenshot of Tcl Version: Tcl Version

Asked By: Peter Steele

||

Answers:

There is nothing wrong with your code. This behavior is system dependent. Menus are under the control of the OS rather than tkinter on OSX and Windows.

Answered By: Bryan Oakley

So revisiting this so many years later. This now works as expected on Windows 11. I am going to assume that the build of windows I was on had a bug causing this with the window manager and was not an issue with the code. I just ran this same code again, and everything is perfect. Just wanted to answer this and let others know that might stumble on it, trying updating your windows install and see if that solves the issue if you are running into a similar problem.

Answered By: Peter Steele
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.