-1

I'm trying to create a window that has a menu bar built into it, but whenever I implement a Tkinter code that creates a menu, it appears at the top next to the Apple logo. How can I make it so that it appears directly in the Tkinter window instead of the OSX menubar?

Here's the code I have so far:

import tkinter as tk
from tkinter.filedialog import askopenfilename

def NewFile():
    print("New File!")
def OpenFile():
    name = askopenfilename()
    print(name)
def About():
    print("This is a simple example of a menu")

root = tk.Tk()
menu = tk.Menu(root)
root.config(menu=menu)
filemenu = tk.Menu(menu)
menu.add_cascade(label="File", menu=filemenu)
filemenu.add_command(label="New", command=NewFile)
filemenu.add_command(label="Open...", command=OpenFile)
filemenu.add_separator()
filemenu.add_command(label="Exit", command=root.quit)

helpmenu = tk.Menu(menu)
menu.add_cascade(label="Help", menu=helpmenu)
helpmenu.add_command(label="About...", command=About)

tk.mainloop()

Any and all help would be appreciated! Thanks.

  • Does this answer your question? [How to make Menu.add\_command() work in tkinter on the Mac?](https://stackoverflow.com/questions/27910640/how-to-make-menu-add-command-work-in-tkinter-on-the-mac) – stovfl May 11 '20 at 21:16
  • Thanks for your quick response. I'm not sure I understand that answer entirely... Does that mean that I can not embed a dropdown menubar directly inside of the Tkinter window? Sorry if my question seems a bit simple, I'm just starting with Tkinter. @stovfl – infinityideas May 11 '20 at 21:21

1 Answers1

0

You can’t do what you want. When you configure a menu for a window there is no way to get non-native behavior.

What you can do instead is create a frame, and in the frame you can add Menubutton widgets. The behavior won’t be exactly the same, but with some work you can create custom bindings to mimic menubar behavior.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685