- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
Example
# 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 win.geometry("700x350") # Create an instance of ttk style s = ttk.Style() s.theme_use('default') s.configure('TNotebook.Tab', background="green3") s.map("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) win.mainloop()
Output
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.
- Related Articles
- Dynamically change the widget background color in Tkinter
- How to change header background color of a table in Java
- How to change the color of ttk button in Tkinter?
- Change the color upon hovering over Button in Tkinter
- How to change the mouse pointer color in Tkinter?
- How to change the background color of a Treeview in Tkinter?
- How to change the color of a Tkinter label programmatically?
- How to fully change the color of a Tkinter Listbox?
- How to change text cursor color in Tkinter?
- How to change the color of a Tkinter rectangle on clicking?
- How to change the background color of a tkinter Canvas dynamically?
- How to change the color of certain words in a Tkinter text widget?
- How to change the menu background color of Tkinter's OptionMenu widget?
- How to make a Button Hover to change the Background Color in Tkinter?
- Default window color Tkinter and hex color codes in Tkinter
