Tkinter Entry - Text color


Tkinter Entry - Text Color

In Tkinter, you can set the color of text in an Entry widget with a required color value.

Tkinter Entry - Text Color
Tkinter Entry with text color of "blue"

To set the text color of an Entry widget in Tkinter, pass required color value to the fg parameter to the Entry class constructor, as shown below.

tk.Entry(window, bg="lightgreen")
tk.Entry(window, bg="#FFFF00")

In this tutorial, you will learn how to set the Entry widget text color with a required color value, with examples.

Examples

1. Set Entry widget text color to blue

In this example, we create a basic Tk window with an Entry widget and set its text color with the "blue" value.

Python Program

import tkinter as tk

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

label = tk.Label(window, text="Enter your input")
label.pack()

# Create an Entry widget with specific text color
entry = tk.Entry(window, fg="blue")
entry.pack()

# Run the application
window.mainloop()

Output

In Windows

In MacOS

Tkinter Entry with text color of "blue"
Tkinter Entry with text color of "blue"

2. Set Entry widget text color to blue with HEX value of "#FF0000"

In this example, we create a basic Tk window with an Entry widget and set its text color with a RGB HEX value of "#FF1122".

Python Program

import tkinter as tk

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

label = tk.Label(window, text="Enter your input")
label.pack()

# Create an Entry widget with specific text color
entry = tk.Entry(window, fg="#FF1122")
entry.pack()

# Run the application
window.mainloop()

Output

In Windows

In MacOS

Tkinter Entry with text color "#FF1122"
Tkinter Entry with text color "#FF1122"

Summary

In this Python Tkinter tutorial, we have seen how to set the text color of an Entry widget in Tkinter, with examples.