In this tutorial, I will explain how to use colors in Python Tkinter to create visually appealing and engaging GUI applications. As a developer, I have encountered the need to customize colors in Tkinter projects to enhance user experience and match client requirements. Throughout this article, I will share my tips and suitable code examples.
Color Representation in Python Tkinter
Tkinter provides several ways to represent colors in your GUI applications. The most common methods include:
- Color Names: Tkinter supports a wide range of predefined color names, such as “red”, “blue”, “green”, etc. For example:
import tkinter as tk
window = tk.Tk()
window.title('PythonGuides')
label = tk.Label(window, text="Hello, John from New York!", bg="lightblue", fg="darkred")
label.pack()
window.mainloop()I executed the above example code you can refer to the screenshot below to see the output.

- Hexadecimal Color Codes: You can specify colors using hexadecimal color codes, which are widely used in web development. For example:
button = tk.Button(window, text="Click me, Emily from California!", bg="#FF8C00", fg="#FFFFFF")
button.pack()I executed the above example code you can refer to the screenshot below to see the output.

- RGB Color Tuples: Tkinter does not directly support RGB tuples like
(255, 165, 0). However, you can convert RGB values to hex format and then use them in Tkinter. For example:
def rgb_to_hex(rgb):
return "#%02x%02x%02x" % rgb # Convert (R, G, B) to Hex
# Define an RGB tuple for light green color
rgb_color = (144, 238, 144)
# Convert RGB to hex format
hex_color = rgb_to_hex(rgb_color)
# Set the background color using hex format
window.configure(bg=hex_color)I executed the above example code you can refer to the screenshot below to see the output.

Read Python Tkinter Separator + Examples
Apply Colors to Tkinter Widgets in Python
Tkinter provides various widgets that you can customize with colors to create visually appealing interfaces. Let’s explore some commonly used widgets and how to apply colors to them.
1. Labels
Labels are used to display text or images in your Tkinter application. You can set the background color using the bg parameter and the text color using the fg parameter. For example:
label = tk.Label(window, text="Welcome, Michael from Texas!", bg="lightgreen", fg="darkblue")
label.pack()I executed the above example code you can refer to the screenshot below to see the output.

Check out How to Generate Payslip using Python Tkinter + Video Tutorial
2. Buttons
Buttons allow users to interact with your application by triggering actions when clicked. You can customize the background color and text color of buttons using the bg and fg parameters, respectively. For example:
def submit_data():
print("Data Submitted!")
button = tk.Button(window, text="Submit", bg="#4CAF50", fg="white", command=submit_data)
button.pack()I executed the above example code you can refer to the screenshot below to see the output.

Read How to convert Python file to exe using Pyinstaller
3. Color Text
foreground or fg is the option that accepts the color input from the user and sets the font or text color. In our example, we will be implementing color on the Text box widget. By default the Text color is blue but we will change it to Blue.
tb = tk.Text(
window,
width=25,
height=8,
font=('Times', 20),
wrap='word',
fg='#4A7A8C'
)
tb.pack(expand=True)I executed the above example code you can refer to the screenshot below to see the output.

Check out Create Word Document in Python Tkinter
4. Canvas
The Canvas widget allows you to draw shapes, and lines, and display images in your Tkinter application. You can set the background color of the canvas using the bg parameter. For example:
canvas = tk.Canvas(window, width=400, height=300, bg="lightblue")
canvas.pack()I executed the above example code you can refer to the screenshot below to see the output.

Read Python Tkinter Filter Function()
5. Color Chooser
Python Tkinter provides a colorchooser module using which color toolbox can be displayed. Color chooser allows users to choose colors from the color tray. colorchooser returns the RGB code with hexadecimal color code in the tuple format. In our example, we will create an application that allows users to choose any color from the color tray, and then that color will be displayed on the label.
from tkinter import colorchooser
def pick_color():
color = tk.colorchooser.askcolor(title ="Choose color")
color_me.config(bg=color[1])
color_me.config(text=color)
color_me = tk.Label(
window,
text='(217, 217, 217) #d9d9d9',
font = ('Times', 20),
relief = tk.SOLID,
padx=20,
pady=20
)
color_me.pack(expand=True)
button = tk.Button(
window,
text = "Choose Color",
command = pick_color,
padx=10,
pady=10,
font=('Times', 18),
bg='#4a7a8c'
)
button.pack()I executed the above example code you can refer to the screenshot below to see the output.

Check out Python Tkinter add function with examples
6. Color Transparent
The first step in the process is to set the background color to the window using the config keyword. now provide the same background color in the wm_attributes()Here is the implementation of Python Tkinter Color Transparent.
window.config(bg='#4a7a8c')
window.wm_attributes('-transparentcolor','#4a7a8c')I executed the above example code you can refer to the screenshot below to see the output.

Read Python Tkinter panel
Create Color Themes
When developing a Tkinter application, it’s often desirable to create a consistent color theme throughout the user interface. Here’s an example of how you can define a color theme and apply it to various widgets:
# Define color theme
theme = {
"primary": "#2196F3",
"secondary": "#FFFFFF",
"accent": "#FF5722",
"background": "#F5F5F5"
}
# Apply color theme to widgets
window.configure(bg=theme["background"])
title_label = tk.Label(window, text="Customer Management System", bg=theme["primary"], fg=theme["secondary"], font=("Arial", 16))
title_label.pack(pady=20)
search_entry = tk.Entry(window, width=30)
search_entry.pack()
search_button = tk.Button(window, text="Search", bg=theme["accent"], fg=theme["secondary"], command=search_customer)
search_button.pack(pady=10)In this example, we define a color theme dictionary called theme with specific colors for primary, secondary, accent, and background elements. We then apply these colors to the window background, title label, search entry, and search button, creating a cohesive and visually appealing interface.
Check out Python Tkinter after method
Handle Color Interactions
When designing interactive Tkinter applications, you may need to handle color changes based on user interactions. For example, you might want to change the color of a button when it’s hovered over or clicked. Here’s an example of how you can achieve this:
def on_enter(event):
event.widget.configure(bg="darkblue")
def on_leave(event):
event.widget.configure(bg="lightblue")
submit_button = tk.Button(window, text="Submit", bg="lightblue")
submit_button.pack(pady=10)
submit_button.bind("<Enter>", on_enter)
submit_button.bind("<Leave>", on_leave)In this code snippet, we define two functions: on_enter and on_leave. These functions are triggered when the mouse pointer enters and leaves the button widget, respectively. We use the configure method to change the background color of the button based on the user interaction.
Check out Python Tkinter save text to file
Conclusion
In this tutorial, I have explained how to master colors in Python Tkinter. I discussed color representation in Python Tkinter and how to apply color to the Tkinter widget like labels, buttons, color text, canvas, color chooser, and color transparent. I also covered creating color themes and handling color interaction.
You may read:

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.