Reputation: 21
I would like to create a menubar on mac os with tkinter. My program runs, but nothing appears on the menubar. I can only see the Python menubar, nothing else is shown. My custom menus don't even show up on the mac menubar. As far as I know it should be visible there. I would appreciate some help. Here is my code:
from tkinter import *
def openFile():
print("File has been opened!")
def saveFile():
print("File has been saved!")
def cut():
print("You cut some text!")
def copy():
print("You copied some text!")
def paste():
print("You pasted some text!")
window = Tk()
menubar = Menu(window)
fileMenu = Menu(menubar,tearoff=0,font=("MV Boli",15))
menubar.add_cascade(label="File",menu=fileMenu)
fileMenu.add_command(label="Open",command=openFile)
fileMenu.add_command(label="Save",command=saveFile)
fileMenu.add_separator()
fileMenu.add_command(label="Exit",command=quit)
editMenu = Menu(menubar,tearoff=0,font=("MV Boli",15))
menubar.add_cascade(label="Edit",menu=editMenu)
editMenu.add_command(label="Cut",command=cut)
editMenu.add_command(label="Copy",command=copy)
editMenu.add_command(label="Save",command=paste)
window.mainloop()
Upvotes: 2
Views: 566
Reputation: 1723
To create a menubar for a window, first, create a menu widget. Then, use the window's menu configuration option to attach the menu widget to the window.
menubar = Menu(window)
window['menu'] = menubar
There are still nuances for Mac OS, read Menus
Upvotes: 2