How to Change Tkinter Label Color in Python

When I first started building desktop applications for local businesses, I realized that standard gray windows were quite boring for users.

Adding a splash of color to your labels can completely change the feel of your application, making it look modern and professional.

In this tutorial, I will show you exactly how to change the background and foreground colors of a Tkinter Label using various methods I’ve used over the years.

The Basics of Tkinter Label Colors

In Tkinter, we primarily deal with two types of color attributes for a Label widget: the background and the foreground.

The ‘foreground’ (fg) refers to the text color, while the ‘background’ (bg) refers to the area behind the text.

You can define these colors using standard names like “red” or “blue,” or use Hexadecimal color codes for greater precision.

Method 1: Set Colors During Label Creation

The most straightforward way to set the color is when you define the Label widget itself.

I often use this method when the UI elements are static and don’t need to change based on user interaction.

Here is a practical example using a simplified “Sales Tax Calculator” interface for a California-based retail app.

import tkinter as tk

# Initialize the main window
root = tk.Tk()
root.title("California Retail Terminal")
root.geometry("400x250")

# Creating a label with specific colors during initialization
# 'fg' is for text color, 'bg' is for background color
tax_label = tk.Label(
    root, 
    text="Total Sales Tax (7.25%): $45.50", 
    font=("Arial", 14, "bold"),
    fg="white", 
    bg="#1e3a8a"  # A deep navy blue often used in corporate apps
)

tax_label.pack(pady=50)

root.mainloop()

I executed the above example code and added the screenshot below.

Change Tkinter Label Color in Python

In this code, I used a Hex code for the background to get a specific shade of navy blue that looks much better than the default “blue” keyword.

Method 2: Use the .config() Method to Update Colors

There are many times when you need to change the color of a label dynamically after the app has already started.

For instance, if a stock price on the New York Stock Exchange goes up, you want the label to turn green; if it goes down, it should turn red.

The .config() (or .configure()) method is your best friend here. It allows you to update any property of the widget on the fly.

Let’s look at an example that simulates a “Budget Status” indicator for a New York department project.

import tkinter as tk

def update_status():
    # Changing the color dynamically based on a condition
    current_status = "OVER BUDGET"
    status_label.config(text=f"Status: {current_status}", fg="white", bg="#b91c1c")

root = tk.Tk()
root.title("NY Department Budget Tracker")
root.geometry("400x300")

status_label = tk.Label(
    root, 
    text="Status: UNDER BUDGET", 
    font=("Helvetica", 12),
    fg="black", 
    bg="#d1d5db"
)
status_label.pack(pady=30)

# Button to trigger the color change
action_button = tk.Button(root, text="Run Budget Check", command=update_status)
action_button.pack()

root.mainloop()

I executed the above example code and added the screenshot below.

Tkinter Label Color in Python

I’ve found that using .config() keeps the code clean because you don’t have to delete and recreate the widget just to change its appearance.

Method 3: Use Dictionary Syntax for Color Changes

Tkinter widgets also allow you to access their properties as if they were a Python dictionary.

I personally use this syntax when I only need to change a single property, like just the text color, without touching the background.

It is concise and very readable for other developers who might review your code.

import tkinter as tk

root = tk.Tk()
root.title("Florida Power Grid Monitor")
root.geometry("400x200")

grid_label = tk.Label(root, text="Grid Status: ACTIVE", font=("Verdana", 14))
grid_label.pack(pady=40)

# Accessing the attribute directly like a dictionary key
grid_label["fg"] = "#15803d" # Forest Green
grid_label["bg"] = "#f0fdf4" # Very light green tint

root.mainloop()

I executed the above example code and added the screenshot below.

How to Change Tkinter Label Color in Python

Understand Color Options in Tkinter

When you are designing apps for a USA-based audience, brand consistency is usually very important.

You aren’t limited to basic names; you can use any of the following:

  1. Standard Names: “red”, “green”, “blue”, “white”, “black”, “yellow”, etc.
  2. Extended Names: Tkinter supports many X11 color names like “ghost white”, “tomato”, “slate blue”, and “navajo white”.
  3. Hexadecimal Codes: This is the industry standard. Codes like #FF5733 give you millions of options.

I always recommend using Hex codes because colors can look slightly different on Windows vs. macOS if you rely on system names.

Change Colors on Mouse Hover (Event Binding)

A great way to improve the user experience of your Python tools is to make them interactive.

You can change the label color when the user moves their mouse over it. This provides immediate visual feedback.

I used this frequently when building internal dashboards for a logistics firm in Texas to highlight clickable items.

import tkinter as tk

def on_enter(event):
    info_label.config(bg="#fef08a", fg="black") # Highlight yellow

def on_leave(event):
    info_label.config(bg="SystemButtonFace", fg="black") # Reset to default

root = tk.Tk()
root.title("Texas Logistics Dashboard")
root.geometry("400x200")

info_label = tk.Label(root, text="Hover here for Shipping Rates", font=("Arial", 12), padx=10, pady=10)
info_label.pack(pady=50)

# Binding mouse events to functions
info_label.bind("<Enter>", on_enter)
info_label.bind("<Leave>", on_leave)

root.mainloop()

Practical Project: A Real-Time US Stock Price Alert

To wrap everything we’ve learned together, let’s build a small utility.

This script simulates a stock monitor where the label color indicates the performance of a tech company like Apple or Microsoft.

This is exactly how I would structure a small monitoring tool for a financial desk.

import tkinter as tk
import random

def check_market():
    # Simulate a price change
    change = random.uniform(-5.0, 5.0)
    price = 150.0 + change
    
    if change >= 0:
        color = "#16a34a" # Green for gain
        trend = "▲"
    else:
        color = "#dc2626" # Red for loss
        trend = "▼"
    
    stock_label.config(
        text=f"NASDAQ: MSFT {price:.2f} {trend} ({change:+.2f})",
        fg=color
    )
    
    # Schedule the next update in 2 seconds
    root.after(2000, check_market)

root = tk.Tk()
root.title("Wall Street Live Tracker")
root.geometry("450x150")
root.configure(bg="#111827") # Dark background for a modern look

stock_label = tk.Label(
    root, 
    text="Connecting to Exchange...", 
    font=("Consolas", 14),
    bg="#111827",
    fg="#9ca3af"
)
stock_label.pack(expand=True)

# Start the live update loop
check_market()

root.mainloop()

This example uses the .after() method, which is a professional way to handle updates in Tkinter without freezing the UI.

Common Issues and Troubleshooting

I have seen many beginners struggle with color names not being recognized.

If you get an error like _tkinter.TclError: unknown color name “customblue”, it means Tkinter doesn’t know that specific string.

Always double-check your spelling or, better yet, use a Hex code to ensure the color is valid.

Another thing to remember is that on some macOS versions, the background color of certain widgets might not behave exactly like Windows due to the system’s “Aqua” theme.

In those cases, using a Canvas or a Frame as a wrapper can help you get the exact look you want.

Summary of Attributes

AttributeDescription
bg / backgroundSets the color of the area behind the text.
fg / foregroundSets the color of the text itself.
activebackgroundThe color when the label is in an active state (less common for labels).
activeforegroundThe text color when the label is active.
highlightbackgroundThe color of the focus highlight when the widget does not have focus.

In this tutorial, I have covered several ways to change the color of a Tkinter Label.

I started with the simplest method of setting colors during creation and then moved to more dynamic ways like using .config() and dictionary syntax.

We also looked at how to make labels interactive with mouse hover events and how to use Hex codes for professional-looking apps.

You may read:

51 Python Programs

51 PYTHON PROGRAMS PDF FREE

Download a FREE PDF (112 Pages) Containing 51 Useful Python Programs.

pyython developer roadmap

Aspiring to be a Python developer?

Download a FREE PDF on how to become a Python developer.

Let’s be friends

Be the first to know about sales and special discounts.