Turns out this piece of code from the matplotlib examples gave me the answer I was after.

The hex codes of the "tableau" palette are as follows:

tab:blue : #1f77b4
tab:orange : #ff7f0e
tab:green : #2ca02c
tab:red : #d62728
tab:purple : #9467bd
tab:brown : #8c564b
tab:pink : #e377c2
tab:gray : #7f7f7f
tab:olive : #bcbd22
tab:cyan : #17becf

Using the following code I made a dictionnary containing all the named colors and their respective hex code :

import matplotlib.colors as mcolors


mcolors.TABLEAU_COLORS
mcolors.XKCD_COLORS
mcolors.CSS4_COLORS
#Base colors are in RGB so they need to be converted to HEX
BASE_COLORS_hex = {name:mcolors.rgb2hex(color) for name,color in mcolors.BASE_COLORS.items()}


all_named_colors = {}
all_named_colors.update(mcolors.TABLEAU_COLORS)
all_named_colors.update(BASE_COLORS_hex)
all_named_colors.update(mcolors.CSS4_COLORS)
all_named_colors.update(mcolors.XKCD_COLORS)


#print(all_named_colors)
print(all_named_colors["tab:blue"])
>>> #1f77b4
Answer from jadsq on Stack Overflow
🌐
XlsxWriter
xlsxwriter.readthedocs.io › example_tab_colors.html
Example: Setting Worksheet Tab Colors — XlsxWriter
# # SPDX-License-Identifier: BSD-2-Clause # # Copyright (c) 2013-2025, John McNamara, jmcnamara@cpan.org # import xlsxwriter workbook = xlsxwriter.Workbook("tab_colors.xlsx") # Set up some worksheets. worksheet1 = workbook.add_worksheet() worksheet2 = workbook.add_worksheet() worksheet3 = workbook.add_worksheet() worksheet4 = workbook.add_worksheet() # Set tab colors worksheet1.set_tab_color("red") worksheet2.set_tab_color("green") worksheet3.set_tab_color("#FF9900") # Orange # worksheet4 will have the default color.
Discussions

How to get/set the colour of the worksheet tab using xlwings in Python?
import xlsxwriter workbook = xlsxwriter.Workbook('tab_colors.xlsx') # Set up some worksheets. More on github.com
🌐 github.com
4
July 7, 2022
How to change the color of a selected tab?
hi, I would like to change the colour of a selected tab, to the background of left blue, and white color for letters More on community.plotly.com
🌐 community.plotly.com
3
0
September 24, 2022
python - Coloring a tab in openpyxl - Stack Overflow
We have a situation where we want to color the tabs for the worksheets using openpyxl. Is there a way to do this within the library? Or, has anyone found a way to do this external to the library ... More on stackoverflow.com
🌐 stackoverflow.com
Tabs Style Colors
Hi all, I’m having this tabs with target text color : white, for all tabs and i want when a user hover the background would change to white and text color to grey for example, because whenever i tried as the documentation suggested it over-write the first style i set Thank you More on community.plotly.com
🌐 community.plotly.com
1
1
April 9, 2023
🌐
iTerm2
iterm2.com › python-api › examples › settabcolor.html
Set Tab Color — iTerm2 Python API 0.26 documentation
#!/usr/bin/env python3.7 import iterm2 async def main(connection): app=await iterm2.async_get_app(connection) session=app.current_terminal_window.current_tab.current_session change = iterm2.LocalWriteOnlyProfile() color = iterm2.Color(255, 128, 128) change.set_tab_color(color) change.set_use_tab_color(True) await session.async_set_profile_properties(change) iterm2.run_until_complete(main) Download ·
🌐
iTerm2
iterm2.com › python-api › examples › app_tab_color.html
Set Tab Color from Current App — iTerm2 Python API 0.26 documentation
This script sets the tab color based on the current app. #!/usr/bin/env python3 import iterm2 import os import random colors = { "vi": (255, 255, 255), "emacs": (255, 0, 0) } async def SetTabColor(connection, session, color): change = iterm2.LocalWriteOnlyProfile() if color: change.set_tab_color(color) change.set_use_tab_color(True) else: change.set_use_tab_color(False) await session.async_set_profile_properties(change) async def UpdateTabColor(connection, session, command): try: parts = command.split(" ") command = os.path.basename(os.path.normpath(parts[0])) r,g,b = colors[command] color = iterm2.Color(r, g, b) await SetTabColor(connection, session, color) except Exception as e: print(e) async def main(connection): app = await iterm2.async_get_app(connection) async def monitor(session_id): """Run for each session, including existing sessions.
🌐
Matplotlib
matplotlib.org › stable › tutorials › colors › colors.html
Matplotlib
January 28, 2021 - Matplotlib has support for visualizing information with a wide array of colors and colormaps. These tutorials cover the basics of how these colormaps look, how you can create your own, and how you can customize colormaps for your use case · For even more information see the examples page
🌐
GitHub
github.com › xlwings › xlwings › issues › 1954
How to get/set the colour of the worksheet tab using xlwings in Python? · Issue #1954 · xlwings/xlwings
July 7, 2022 - worksheet1 = workbook.add_worksheet() worksheet2 = workbook.add_worksheet() worksheet3 = workbook.add_worksheet() worksheet4 = workbook.add_worksheet() # Set tab colors worksheet1.set_tab_color('red') worksheet2.set_tab_color('green') worksheet3.set_tab_color('#FF9900') # Orange # worksheet4 will have the default color.
Author: xlwings
Find elsewhere
Top answer
1 of 5
23

You can try creating a custom theme.

import tkinter as tk
from tkinter import ttk

root = tk.Tk()

mygreen = "#d2ffd2"
myred = "#dd0202"

style = ttk.Style()

style.theme_create( "yummy", parent="alt", settings={
        "TNotebook": {"configure": {"tabmargins": [2, 5, 2, 0] } },
        "TNotebook.Tab": {
            "configure": {"padding": [5, 1], "background": mygreen },
            "map":       {"background": [("selected", myred)],
                          "expand": [("selected", [1, 1, 1, 0])] } } } )

style.theme_use("yummy")

note = ttk.Notebook(root)
f1 = ttk.Frame(note, width=300, height=200)
note.add(f1, text = 'First')
f2 = ttk.Frame(note, width=300, height=200)
note.add(f2, text = 'Second')
note.pack(expand=1, fill='both', padx=5, pady=5)

tk.Button(root, text='yummy!').pack(fill='x')

root.mainloop()

EDIT

The most detailed ttk documentation is from the tcl/tk world

eg.

http://www.tcl.tk/man/tcl/TkCmd/ttk_notebook.htm

For some useful python-based examples, you can grab the pyttk-samples package from http://code.google.com/p/python-ttk/

2 of 5
13

I had been using Oblivion's answer for some time, but I encountered an issue where the open/save dialog button outlines disappeared and Checkbuttons in Text widgets never appeared to be checked (even when they were checked). So, I translated the theme code into some style configuration and such to solve the problem (it solved it). This will let you change the tab bar color, the tab background/foreground and the active tab background/foreground. Plus, it won't cause issues with the rest of your chosen theme. It's essentially the same code from the theme translated over. So, really, Oblivion deserves most of the credit.

Style().configure("TNotebook", background=myTabBarColor);
Style().map("TNotebook.Tab", background=[("selected", myActiveTabBackgroundColor)], foreground=[("selected", myActiveTabForegroundColor)]);
Style().configure("TNotebook.Tab", background=myTabBackgroundColor, foreground=myTabForegroundColor);

Edit: Apparently, this solution doesn't work in Windows. I tested it in Linux (a number of versions of Xubuntu).

🌐
GitHub
github.com › python › cpython › issues › 130472
Use colors in tab-completion in PyREPL · Issue #130472 · python/cpython
February 22, 2025 - stdlibStandard Library Python modules ... Library Python modules in the Lib/ directorytopic-replRelated to the interactive shellRelated to the interactive shelltype-featureA feature request or enhancementA feature request or enhancement ... The current tab-completer is somewhat basic. There's a pyrepl-based library called fancycompleter that allows for context-aware colorful tab ...
Author: python
🌐
Stack Overflow
stackoverflow.com › questions › 72773963 › python-tkinter-howto-set-individual-colors-for-notebook-tabs
Python tkinter: Howto set individual colors for Notebook tabs? - Stack Overflow
from tkinter import * from tkinter import ttk mygreen = "#d2ffd2" myred = "#dd0202" root = Tk() tabsystem = ttk.Notebook(master=root) text1=Text(tabsystem, state = DISABLED) text2=Text(tabsystem, state = DISABLED) text3=Text(tabsystem, state = DISABLED) tabsystem.add(text1,text="Text 1") ttk.Style().configure("TNotebook.Tab", background=myred) tabsystem.add(text2,text="Text 2") ttk.Style().configure("TNotebook.Tab", background=mygreen) tabsystem.add(text3,text="Text 3") ttk.Style().configure("TNotebook.Tab", background=myred) tabsystem.grid(row=0) mainloop()
🌐
Reddit
reddit.com › r/maya › change tab colors with python?
r/Maya on Reddit: Change tab colors with python?
February 11, 2020 - Is this done with cmds or Qt? With cmds, if you're using tabLayout, there should be a bgc flag to set the colour.
🌐
Medium
medium.com › top-python-libraries › colors-of-python-visualization-matplotlib-built-in-cc802d9ac06b
Colors of Python visualization — Matplotlib built-in | by ZHEMING XU | Top Python Libraries | Medium
July 29, 2025 - (8) Colormap in Tableau like ‘tab:blue’. 2. How to use colors in matplotlib · # From official site import matplotlib.pyplot as plt import numpy as np t = np.linspace(0.0, 2.0, 201) s… · 5.1K followers · ·Last published Aug 31, 2026 · Python is widely used in fields such as data analysis, machine learning, and web development.
🌐
DataScientYst
datascientyst.com › full-list-named-colors-pandas-python-matplotlib
Full List of Named Colors in Pandas and Python
March 31, 2023 - ['magma', 'inferno', 'plasma', 'viridis', 'cividis', 'twilight', 'twilight_shifted', 'turbo', 'Blues', 'BrBG', 'BuGn', 'BuPu', 'CMRmap', 'GnBu', 'Greens', 'Greys', 'OrRd', 'Oranges', 'PRGn', 'PiYG', 'PuBu', 'PuBuGn', 'PuOr', 'PuRd', 'Purples', 'RdBu', 'RdGy', 'RdPu', 'RdYlBu', 'RdYlGn', 'Reds', 'Spectral', 'Wistia', 'YlGn', 'YlGnBu', 'YlOrBr', 'YlOrRd', 'afmhot', 'autumn', 'binary', 'bone', 'brg', 'bwr', 'cool', 'coolwarm', 'copper', 'cubehelix', 'flag', 'gist_earth', 'gist_gray', 'gist_heat', 'gist_ncar', 'gist_rainbow', 'gist_stern', 'gist_yarg', 'gnuplot', 'gnuplot2', 'gray', 'hot', 'hsv',
🌐
Oraask
oraask.com › home › wiki - article
Python Matplotlib Colors - 15+ Practical Examples - Oraask
March 7, 2023 - The bar chart in python matplotlib is the graph represented by rectangles. These graphs are best used for comparison purposes. We can pass arguments to give different colors to the graphs’ bars. The color codes are the same. We can pass the color arguments in the form of the primary color, tab color, etc.
🌐
Kaggle
kaggle.com › code › asimislam › python-colors-color-cmap-palette
Python Colors for COLOR, CMAP and PALETTE
2 weeks ago - Checking your browser before accessing www.kaggle.com · Click here if you are not automatically redirected after 5 seconds
Top answer
1 of 1
1

Your question has more to do with ttk style Custom.TNotebook than canvas.

One way to achieve the effect is to create your own theme.

'mytheme' defines new values for Scrollbar, Frame and Notebook.

import tkinter as tk
from tkinter import ttk

master = tk.Tk()
# Create your own Style theme
style = ttk.Style(master)

# Define your color scheme
RED = "#ff0000"
ORANGE = "#ffa500"
YELLOW = "#ffff00"
TROUGH = "#668877"

style.theme_create(
    "mytheme",
    parent = "default",
    settings = {
        "TScrollbar": {
            "configure": {
                "background": YELLOW,
                "troughcolor": TROUGH,
                "lightcolor": ORANGE,
                "borderwidth": 1},
            "map": {
                "background": [("active", ORANGE),
                               ("disabled", YELLOW)],
                "arrowcolor": [("active", YELLOW),
                               ("disabled", ORANGE)]}},
        "TFrame": {
                "configure": {
                    "background": RED}},
        "TNotebook": {
            "configure":
            {
                "background": ORANGE}},
        "TNotebook.Tab": {
            "configure":
            {
                "background": ORANGE},
            "map": {
                "background": [("selected", RED)]}}})

style.theme_use("mytheme")

master.rowconfigure(0, weight = 1)
master.columnconfigure(0, weight = 1)

tab = ttk.Notebook(master)
tab1 = ttk.Notebook(tab)
tab2 = ttk.Notebook(tab)
  
tab.add(tab1, text = "Tab 1")
tab.add(tab2, text = "Tab 2")

# changed place manager so tkinter can calculate master size.
tab.grid(row = 0, column = 0, sticky = tk.NSEW)

#tab 1
a = ttk.Frame(tab1)
# canvas needs scrollregion and remove all surrounding space
canvas = tk.Canvas(
    a,
    background = RED, highlightthickness = 0,
    borderwidth = 0, scrollregion = "0 0 1000 1000")
# important! pack canvas
canvas.grid(row = 0, column = 0, sticky = tk.NSEW)

scrollbar = ttk.Scrollbar(
    a, orient = tk.VERTICAL, command = canvas.yview)
scrollbar.grid(row = 0, column = 1, sticky = tk.NS)
# important! connect canvas to scrollbar
canvas["yscrollcommand"] = scrollbar.set

b = ttk.Frame(tab1)
tab1.add(a, text = "X")
tab1.add(b, text = "Y")

#tab 2
c = ttk.Frame(tab2)
d = ttk.Frame(tab2)
tab2.add(c, text = "A")
tab2.add(d, text = "B")

master.mainloop()
🌐
pyRevit
discourse.pyrevitlabs.io › tools
Tab colourizing code - Tools - pyRevit Forums
June 25, 2024 - I would like to experiment with additional ways of colourizing the open tabs – perhaps something where I could force a particular tab to have a red border so I can quickly see which one to return to after looking at a di…
🌐
iTerm2
iterm2.com › python-api › examples › copycolor.html
Preserve Tab Color — iTerm2 Python API 0.26 documentation
This script copies the old tab color to the new split pane so they stay in sync. This script demonstrates how to modify a session’s profile without modifying the underlying profile (which might affect other sessions). #!/usr/bin/env python3.7 import iterm2 async def main(connection): async def async_color_in_tab(tab, exclude): """Return the tab color of any session that already existed.""" colors = [] for session in tab.sessions: if session == exclude: continue profile = await session.async_get_profile() if not profile: continue color = profile.tab_color if color: return color return None ap