Sep-09-2018, 08:59 PM
You needed to provide window info to menu class:
Application.py
Application.py
import tkinter from menuBar import MenuBar class Application: def __init__(self): # Create and display a test window for viewing the menus window = tkinter.Tk() window.minsize(500, 500) # Create an instance of the MenuBar class and display it to the window mb = MenuBar(window) # window.config(menu = mb) window.mainloop() if __name__ == '__main__': Application()menuBar.py
import tkinter class MenuBar: def __init__(self, window): # Create and display the main menu bar menuBar = tkinter.Menu(window) # Create a pull-down menu for file operations fileMenu = tkinter.Menu(menuBar, tearoff = False) fileMenu.add_command(label = "New") fileMenu.add_command(label = "Open...") fileMenu.add_command(label = "Close") fileMenu.add_command(label = "Exit") menuBar.add_cascade(menu = fileMenu, label = "File") # Create a pull-down menu for editing operations editMenu = tkinter.Menu(menuBar, tearoff = False) editMenu.add_command(label = "Cut") editMenu.add_command(label = "Copy") editMenu.add_command(label = "Paste") editMenu.add_command(label = "Select All") editMenu.add_command(label = "Undo") editMenu.add_command(label = "Redo") menuBar.add_cascade(menu = editMenu, label = "Edit") # Create a pull-down menu for help operations helpMenu = tkinter.Menu(menuBar, tearoff = False) helpMenu.add_command(label = "About") menuBar.add_cascade(menu = helpMenu, label = "Help") window.config(menu=menuBar)