Tkinter Label – Foreground (Text) Color

Tkinter Label with Foreground (Text) Color

To set a specific foreground color for a Label widget in Tkinter, pass required color value as argument to the fg (foreground) parameter of Label() constructor. The foreground color determines the color of the text displayed on the label.

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

Syntax to set specific foreground color for a Label in Tkinter

The syntax to set specific foreground color for a Label widget using fg parameter is

tk.Label(window, text="Hello World!", fg="red")

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

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

Examples

1. Label with red foreground color

In this example, we shall create a Label with red foreground 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 foreground color
label = tk.Label(window, text="Hello World!", fg="red")

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

# Run the application
window.mainloop()

Output

Run on a MacOS.

2. Label with HEX foreground color of “#2233FF”

In this example, we shall create a Label with a HEX foreground color of #2233FF, 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 foreground color
label = tk.Label(window, text="Hello World!", fg="#2233FF")

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

# Run the application
window.mainloop()

Output

Run on a MacOS.

Summary

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

Related Tutorials

Privacy Policy Terms of Use

SitemapContact Us