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