'Python tkinter change default entry widget background color
Python tkinter change default entry widget background color
I am trying to change the default background colour for the "Entry" widget without success. Below is the code I have and none of them work. How do I make it work?
Environment: Python 3.10.0 Windows 21H1
import tkinter as objTK
from tkinter import ttk as objTTK
objWindow = objTK.Tk()
objStyle = objTTK.Style()
objStyle.theme_use("clam")
objStyle.map("TEntry", background=[("readonly", "blue")], \
fieldbackground=[("readonly", "blue")], \
disabledbackground=[("readonly", "blue")])
objEntry = objTK.Entry(master=objWindow, width=10)
objEntry.place(x=10, y=10)
objEntry.insert(0, "Test")
objEntry.config(state="readonly")
objWindow.geometry("100x100")
objWindow.bind("<Escape>", lambda _: objWindow.destroy())
objWindow.mainloop()
Solution 1:[1]
You probably have find it yourself by now but just for the ones searching the answer.
To work the Entry must be a ttk.Entry not a tk.Entry just change to
objEntry = objTTK.Entry(master=objWindow, width=10)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
