Hide or removing a menubar of tkinter in python

Question:

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 🙁

Asked By: Cabu

||

Answers:

Is this what you’re looking for:

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():
    menubar.delete(0, END)

remove_button = Button(root, text="Remove", command=remove_func)
remove_button.pack()

?

Answered By: Parviz Karimli

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)
Answered By: Parviz Karimli

Just FYI, I know this question is old and has an accepted answer but this worked for me on tkinter version 8.6 Python 3

my_tk.config(menu="")

For some reason an empty string works but not None

Answered By: ragardner
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.