Python Forum

Full Version: MenuBar hidden when new window opens
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Got my first menu working based on this code from the web. Problem is the menu commands disappear when a menu item is selected. Is there some way to keep it visible? Thanks

from tkinter import *

def donothing():
    filewin = Toplevel(root)
    button = Button(filewin, text="Do nothing button")
    button.pack()

root = Tk()
menubar = Menu(root)
filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label="New", command=donothing)
filemenu.add_command(label="Open", command=donothing)
menubar.add_cascade(label="File", menu=filemenu)

root.config(menu=menubar)
root.mainloop()
See Namespace flooding with * imports

I tried the code, I don't know what you mean by the menu commands disappearing when a menu item is selected as I was able to reuse the menu and select another menu item.
What do you mean by "Is there some way to keep it visible?" When I run your code the new windows partially occlude the menubar. Do you want the new windows to be drawn somewhere else so the main window remains completely visible? Or are you asking if there is a way to keep the file menu open so you don't have to click on the file menu each time to see the options?
Clicking "File" shows New/Open:

[attachment=1986]

Then clicking Open opens a small panel but hides the New/Open

[attachment=1987]

Yes, the list can be reopened by clicking on File again but it would be nice if this list stayed open. If that's the way tkinter works that's fine but I thought I might be missing something.

Thanks, and sorry about the formatting.
That is the way all menus work. If you want it to work differenly use a different control. Maybe some buttons?
Thanks, that's fine now I know how it works