Change the color of "tab header" in ttk.Notebook (tkinter)


Tabs are very useful for a multipurpose GUI application. It helps to isolate the several tasks or processes within the application in the form of tabs. Tabs are very useful for processing multiple tasks at a time. With the help of Tkinter Notebook widget, we can create Tabs in our tkinter application.

To configure the property or style of the tabs, we must have to use a ttk themed widget. The ttk themed widget helps to style any widget present in the application. To configure the background color of the tab, you can use ttk 'default' theme along with passing 'TNotebook.Tab' as the style parameter in configuration.


# Import the required libraries
from tkinter import *
from tkinter import ttk

# Create an instance of tkinter frame
win = Tk()

# Set the size of the tkinter window

# Create an instance of ttk style
s = ttk.Style()
s.configure('TNotebook.Tab', background="green3")"TNotebook", background= [("selected", "green3")])

# Create a Notebook widget
nb = ttk.Notebook(win)

# Add a frame for adding a new tab
f1= ttk.Frame(nb, width= 400, height=180)

# Adding the Tab Name
nb.add(f1, text= 'Tkinter-1')
f2 = ttk.Frame(nb, width= 400, height=180)
nb.add(f2, text= "Tkinter-2")

nb.pack(expand= True, fill=BOTH, padx= 5, pady=5)


Executing the above code will display customized tabs in the window. You can modify the color of the tab by adding the color name in the configuration.

Published on 08-Jun-2021 09:40:35