sticky Option of Notebook ( tabs )

ttk Notebook sticky option

Tkinter Notebook to create tabs and managing options to add image underline state with click events


We can manage the alignment of child window inside the pane by using sticky option through buttons.
Here four buttons are used to align the child window in four corners using different values of sticky option.
Note that this will work with grid layout manager.

sticky option

Values can be n,s,w,e ( North, south, west, east) and combination of chars. Full code is here
import tkinter  as tk 
from tkinter import *
from tkinter import ttk
my_w = tk.Tk()
my_w.geometry("400x200")  

my_tabs = ttk.Notebook(my_w) # declaring 

tab1 = ttk.Frame(my_tabs)
tab2 = ttk.Frame(my_tabs)

my_tabs.add(tab1, text ='Tab-0') # adding tab
my_tabs.add(tab2, text ='Tab-1') # adding tab 
my_tabs.pack(expand = 1, fill ="both")

l1=tk.Label(tab1,text='I am tab-0',bg='yellow',width=10)
l1.place(relx=0.4,rely=0.2) # using place
b1=tk.Button(tab1,text='I am tab 0')
b1.place(relx=0.4,rely=0.4) 

l2=tk.Label(tab2,text='I am tab-1',bg='yellow',width=10)
l2.grid(row=1,column=2) # using grid 
b2=tk.Button(tab2,text='I am tab-1')
b2.grid(row=2,column=2)

b3=tk.Button(my_w,text='ne',
     command=lambda:my_tabs.tab(tab2,sticky='ne'))
b3.pack(side=LEFT)
b4=tk.Button(my_w,text='nw',
     command=lambda:my_tabs.tab(tab2,sticky='nw'))
b4.pack(side=LEFT)
b5=tk.Button(my_w,text='se',
     command=lambda:my_tabs.tab(tab2,sticky='se'))
b5.pack(side=LEFT)
b6=tk.Button(my_w,text='sw',
     command=lambda:my_tabs.tab(tab2,sticky='sw'))
b6.pack(side=LEFT)

my_w.mainloop()  # Keep the window open

Notebook

hide() forget() and select() Methods Tab Option state underline image
On Tab change event to display Tab Number
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer