Tkinter Label – Background Color

Tkinter Label with specific background color

To set a specific background color for a Label widget in Tkinter, pass required color value as argument to the bg parameter of Label() constructor.

Tkinter Label - Background Color

In this tutorial, you will learn how to set a specific background color for a Label widget, with examples.

Syntax to set specific background color for Label in Tkinter

The syntax to set specific background color for a Label widget using bg parameter is

tk.Label(window, text="Hello World!", bg="yellow")

You can also pass RGB HEX values for bg parameter as shown in the following.

tk.Label(window, text="Hello World!", bg="#FF0000")

Examples

1. Label with yellow background color

In this example, we shall create a Label with yellow background color, and display it in the main window.

Program

import tkinter as tk

# Create the main window
window = tk.Tk()
window.title("PythonExamples.org")
window.geometry("300x200")

# Create a label widget with background color
label = tk.Label(window, text="Hello World!", bg="yellow")

# Pack the label widget to display it
label.pack()

# Run the application
window.mainloop()

Output

Run on a MacOS.

Tkinter Label with yellow background color

2. Label with HEX background color of “#E8B4FF”

In this example, we shall create a Label with a HEX background color of #E8B4FF, and display it in the main window.

Program

import tkinter as tk

# Create the main window
window = tk.Tk()
window.title("PythonExamples.org")
window.geometry("300x200")

# Create a label widget with HEX value background color
label = tk.Label(window, text="Hello World!", bg="#E8B4FF")

# Pack the label widget to display it
label.pack()

# Run the application
window.mainloop()

Output

Run on a MacOS.

Tkinter Label with HEX background color

Summary

In this Python Tkinter tutorial, we learned how to set a specific background color for a Label widget, with examples.

Code copied to clipboard successfully 👍