import tkinter as tk
from tkinter import ttk
class App(tk.Frame):
def __init__(self, master=None):
super().__init__(master)
self.master = master
self.create_widgets()
def create_widgets(self):
self.notebook = ttk.Notebook(self.master)
self.notebook.pack(side="top", anchor="n", expand=True)
# create tabs
self.tabs = {}
self.tabs["tab1"] = tk.Frame(self.notebook, width=420, height=420, borderwidth=0)
self.tabs["tab2"] = tk.Frame(self.notebook, width=420, height=420, borderwidth=0)
self.tab_headers = ["tab1", "tab2"]
self.tabs["tab1"].pack()
self.tabs["tab2"].pack()
# add frame with label below notebook
self.bottom_frame = tk.Frame(self.master, bg="#ffff00")
self.bottom_frame.pack(side="top", anchor="n", fill="x")
self.bottom_label = tk.Label(self.bottom_frame, text="This is a label below the notebook", font=("TkDefaultFont", 14), bg="#ffff00")
self.bottom_label.pack(side="top", pady=10)
# add tabs to notebook
self.notebook.add(self.tabs["tab1"], text='Tab 1')
self.notebook.add(self.tabs["tab2"], text='Tab 2')
root = tk.Tk()
root.geometry("420x840")
root.resizable(False, False)
app = App(master=root)
app.mainloop()
How do you get the frame/label below the notebook to be packed directly below the notebook? Even after trying side=top and anchor=n, it still aligns to the bottom of the window, even when there is clearly enough room for it to be aligned further up.
Even after trying side=top and anchor=n, it still aligns to the bottom of the window, even when there is clearly enough room for it to be aligned further up.
>Solution :
It is because you have used expand=True in self.notebook.pack(...), so the notebook will use all the available space and the bottom frame will be pushed to the bottom of the window.
If you just use self.notebook.pack(), then the bottom frame will be just below the notebook:

