Python Forum
[Tkinter] MenuBar hidden when new window opens
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] MenuBar hidden when new window opens
#1
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()
Yoriz write Sep-14-2022, 05:22 AM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
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.
Larz60+ likes this post
Reply
#3
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?
Reply
#4
Clicking "File" shows New/Open:

   

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

   

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.
Reply
#5
That is the way all menus work. If you want it to work differenly use a different control. Maybe some buttons?
Reply
#6
Thanks, that's fine now I know how it works
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 539 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  [Tkinter] tkinter menubar not showing on mac ventura taras 1 2,106 Dec-17-2022, 02:44 PM
Last Post: Yoriz
  [Tkinter] GUI Opens Minimized gw1500se 24 5,878 May-05-2022, 04:12 PM
Last Post: deanhystad
  [Tkinter] Exclude hidden file, filedialog.askopenfile red380sl 1 3,188 Dec-01-2020, 07:04 PM
Last Post: DT2000
  [PyQt] Drag and Move window from menubar WBPYTHON 3 4,793 Apr-03-2020, 06:15 PM
Last Post: deanhystad
  tkinter window and turtle window error 1885 3 6,752 Nov-02-2019, 12:18 PM
Last Post: 1885
  update a variable in parent window after closing its toplevel window gray 5 9,118 Mar-20-2017, 10:35 PM
Last Post: Larz60+
  [Tkinter] Make A Button That Opens Another Tk() Window That I Have Made Saif133 5 28,349 Jan-20-2017, 08:10 PM
Last Post: scriptso

Forum Jump:

User Panel Messages

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