Search code examples
pythonpython-3.xtkintermenu

Hide or removing a menubar of tkinter in python


I can set my menu with the following instruction:

my_tk.config(menu=my_menu_bar)

But, How do I remove it or hide it completely?

my_tk.config(menu=None)

doesn't work :-(


Solution

  • Another way is:

    from tkinter import *
    root = Tk()
    
    menubar = Menu(root)
    root.config(menu=menubar)
    
    submenu = Menu(menubar)
    menubar.add_cascade(label="Submenu", menu=submenu)
    submenu.add_command(label="Option 1")
    submenu.add_command(label="Option 2")
    submenu.add_command(label="Option 3")
    
    def remove_func():
        emptyMenu = Menu(root)
        root.config(menu=emptyMenu)
    
    remove_button = Button(root, text="Remove", command=remove_func)
    remove_button.pack()
    

    What's different:
    in

    def remove_func():
    

    created an empty menu

    emptyMenu = Menu(root)
    

    and replaced it with the current menu (menubar)

    root.config(menu=emptyMenu)