Python Forum
Menu bar not showing in gui window
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Menu bar not showing in gui window
#2
You needed to provide window info to menu class:

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)
Reply


Messages In This Thread
Menu bar not showing in gui window - by mlh - Sep-09-2018, 07:09 PM
RE: Menu bar not showing in gui window - by Larz60+ - Sep-09-2018, 08:59 PM
RE: Menu bar not showing in gui window - by mlh - Sep-09-2018, 10:27 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 541 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  [PyQt] QWidgetAction of QFrame not showing in menu malonn 4 2,031 Sep-22-2022, 10:49 PM
Last Post: malonn
  [PyQt] Matplotlib figure not showing cursor coordinates in the figure window mart79 0 2,092 Mar-26-2020, 01:48 PM
Last Post: mart79
  tkinter window and turtle window error 1885 3 6,752 Nov-02-2019, 12:18 PM
Last Post: 1885
  [Tkinter] Tkinter optionmenu child menu position showing 0,0 thatguy14 2 4,670 Jun-15-2018, 10:42 AM
Last Post: thatguy14
  [Tkinter] No menu bar in window bde69 5 10,880 Nov-25-2017, 06:35 PM
Last Post: heiner55
  update a variable in parent window after closing its toplevel window gray 5 9,128 Mar-20-2017, 10:35 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020