Sep-09-2018, 07:09 PM
Hello all,
I am needing to learn tkinter to complete a a gui project. I would like to be able to separate the components that I need to code into their own classes and files. The job that I have, is to create the menu bar for an application. For testing purposes, I have created an Application class and would like to be able to call my MenuBar class from within the Application class. Everything works, except when I run the application, the gui window does not show any menus. Python is not my "native" language, so I am having to learn Python on top of learning tkinter. I am running Python on Windows 10. Also, this is my first post in this forum, so please excuse me for any shortcomings.
Here are my files:
Application.py
I am needing to learn tkinter to complete a a gui project. I would like to be able to separate the components that I need to code into their own classes and files. The job that I have, is to create the menu bar for an application. For testing purposes, I have created an Application class and would like to be able to call my MenuBar class from within the Application class. Everything works, except when I run the application, the gui window does not show any menus. Python is not my "native" language, so I am having to learn Python on top of learning tkinter. I am running Python on Windows 10. Also, this is my first post in this forum, so please excuse me for any shortcomings.
Here are my files:
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.config(menu = mb) window.mainloop() Application()menuBar.py
import tkinter class MenuBar: def __init__(self): # Create and display the main menu bar menuBar = tkinter.Menu() # Create a pull-down menu for file operations fileMenu = tkinter.Menu(master = None, tearoff = False) menuBar.add_cascade(menu = fileMenu, label = "File") fileMenu.add_command(label = "New") fileMenu.add_command(label = "Open...") fileMenu.add_command(label = "Close") fileMenu.add_command(label = "Exit") # Create a pull-down menu for editing operations editMenu = tkinter.Menu(master=None, tearoff = False) menuBar.add_cascade(menu = editMenu, label = "Edit") 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") # Create a pull-down menu for help operations helpMenu = tkinter.Menu(master = None, tearoff = False) menuBar.add_cascade(menu = helpMenu, label = "Help") helpMenu.add_command(label = "About")