Cabu
Cabu

Reputation: 564

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 :-(

Upvotes: 3

Views: 11841

Answers (3)

ragardner
ragardner

Reputation: 1975

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

Upvotes: 4

Parviz Karimli
Parviz Karimli

Reputation: 1287

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)

Upvotes: 3

Parviz Karimli
Parviz Karimli

Reputation: 1287

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

?

Upvotes: 3

Related Questions