Tkinter Entry - Background Color


Tkinter Entry - Background Color

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

Tkinter Entry with lightgreen background color

To set the background color of an Entry widget in Tkinter, pass required color value to the bg 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 background color of an Entry widget with a required color value, with examples.

Examples

1. Set light green color for the Entry widget background

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

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
entry = tk.Entry(window, bg="lightgreen")
entry.pack()

# Run the application
window.mainloop()

Output

In Windows

In MacOS

Tkinter Entry with lightgreen background color

2. Set background color of Entry widget with HEX value of "#FFFF00"

In this example, we create a basic Tk window with an Entry widget and set its background color with the "#FFFF00".

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
entry = tk.Entry(window, bg="#FFFF00")
entry.pack()

# Run the application
window.mainloop()

Output

In Windows

In MacOS

Tkinter Entry with background color "#FFFF00"

Summary

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