Python Tkinter getting the topbar above the menubar

I’m creating my own Notepad based on the default Windows Notepad app. The default app has a bar between the title bar and menu bar, which displays the name of the text file and allows the user to open new tabs; (most likely using the Notebook function). Yet no matter what I try, the topbar appears below the menubar. How do I get the topbar to display above the menubar?

Here is my code:

from tkinter import *
from tkinter import ttk
from file_functions import *

#create main window
root = Tk()
root.title("Justin's Notepad")
root.geometry('400x300')


#create a frame for the topbar
topbar = ttk.Frame(root)
topbar.grid(column=0, row=0, sticky=(W,E,N))
#filename label
file_name = ttk.Label(topbar, text='Untitled')
file_name.grid(column=0, row=0)


#THE MENUBAR
#create a frame for the menubar
menuframe = ttk.Frame(root)
menuframe.grid(column=1, row=1)
#create the menubar
menubar = Menu(menuframe)
#menu drop-downs
menubar_file = Menu(menubar, tearoff=0)
menubar_edit = Menu(menubar, tearoff=0)
menubar_view = Menu(menubar, tearoff=0)
menubar.add_cascade(menu=menubar_file, label='File')
menubar.add_cascade(menu=menubar_edit, label='Edit')
menubar.add_cascade(menu=menubar_view, label='View')
#menu options for "file" menu
menubar_file.add_command(label='New Tab', accelerator='Ctrl+N')
menubar_file.add_command(label='New Window', accelerator='Ctrl+Shift+N')
menubar_file.add_command(label='Open', accelerator='Ctrl+O', command=open_file)
menubar_file.add_command(label='Save', accelerator='Ctrl+S')
menubar_file.add_command(label='Save As', accelerator='Ctrl+Shift+S')
menubar_file.add_command(label='Save All', accelerator='Ctrl+Alt+S')
menubar_file.add_separator()
menubar_file.add_command(label='Page Setup')
menubar_file.add_command(label='Print', accelerator='Ctrl+P')
menubar_file.add_separator()
menubar_file.add_command(label='Close Tab', accelerator='Ctrl+W')
menubar_file.add_command(label='Close Window', accelerator='Ctrl+Shift=W')
menubar_file.add_command(label='Exit', command=root.quit)
#menu options for "edit" menu
menubar_edit.add_command(label='Undo', accelerator='Ctrl+Z')
menubar_edit.add_separator()
menubar_edit.add_command(label='Cut', accelerator='Ctrl+X')
menubar_edit.add_command(label='Copy', accelerator='Ctrl+C')
menubar_edit.add_command(label='Paste', accelerator='Ctrl+V')
menubar_edit.add_command(label='Delete', accelerator='Del')
menubar_edit.add_separator()
menubar_edit.add_command(label='Search With Bing', accelerator='Ctrl+E')
menubar_edit.add_separator()
menubar_edit.add_command(label='Find', accelerator='Ctrl+F')
menubar_edit.add_command(label='Find Next', accelerator='F3')
menubar_edit.add_command(label='Find Previous', accelerator='Shift+F3')
menubar_edit.add_command(label='Replace', accelerator='Ctrl+H')
menubar_edit.add_command(label='Goto', accelerator='Ctrl+G')
menubar_edit.add_separator()
menubar_edit.add_command(label='Select All', accelerator='Ctrl+A')
menubar_edit.add_command(label='Time/Date', accelerator='F5')
menubar_edit.add_separator()
menubar_edit.add_command(label='Font')
#menu options for "view" menu
zoom_menu = Menu(menubar_view)
menubar_view.add_cascade(menu=zoom_menu, label="Zoom")
zoom_menu.add_command(label='Zoom In', accelerator='Ctrl+Plus')
zoom_menu.add_command(label='Zoom Out', accelerator='Ctrl+Minus')
zoom_menu.add_command(label='Restore Default Zoom', accelerator='Ctrl+0')
status_check = StringVar
menubar_view.add_checkbutton(label='Status Bar', variable=status_check, onvalue=1, offvalue=0)
wrap_check = StringVar
menubar_view.add_checkbutton(label='Word Wrap', variable=wrap_check, onvalue=1, offvalue=0)
#add menu bar to root window
root.config(menu=menubar)

root.mainloop()

I don’t think it’s your problem. Windows 11 has the new tab feature, but tkinter relies on tcl/tk which doesn’t support this feature

1 Like

Interesting, so tkinter does not have the feature which Notepad uses. Therefore my program with be a little different.

I think this is a limitation of the native Windows menubar, which Tk uses but the new Notepad version apparently doesn’t, from the looks of it.

According to Microsoft’s documentation on menus:

You cannot assign a menu to a window that is a child window.

So the native menubar can only be assigned to a top-level window and is positioned by the native Windows UI library.

1 Like

I wouldn’t call them ugly, just old-fashioned. Old-fashioned doesn’t mean ugly. Current design trends will soon become old-fashioned, but they’re not ugly now.

1 Like

The version of tcl/tk installed by the python.org Windows and Mac installers are the latest 8.6 versions, less than a year old. 8.7 and 9.0 are still in beta. Meme-thought putdowns, like this and ‘ugly’ are out of place here. They do not help anyone except your ego.

I do not have Win 11 available, so I do not know the full behavior of its new tabs. The closest you could come with tkinter is to use a ttk.Notebook and put 3 Menu buttons at the top of the Frame attached to each tab. My uses thereof are idlelib.configdialog (Notebook) and idlelib.help (Menubutton).