简体   繁体   中英

Changing background color of ttk entry widget

I'm trying to change the background color of a ttk entry widget. I read this post ttk Entry background colour but I don't quite understand the element create stuff. Plus, its quite old. So I thought I'd ask here if there's an easier way to change the background color of a ttk widget or if there isn't, then what would I do to change it?

My current code is simply defining an entry widget and setting its background like this:

colorEntry = ttk.Entry(root, background='black')

I've also used styles but that hasn't worked either.

style = ttk.Style()
style.configure("TEntry", background='black')

Both these methods don't do anything to the background. If I try to change any other property like foreground, they work. I'm on windows 10 and using python 3.8.3.

When creating a Style() widget you also need to apply it to the widget you want to change style to.

colorEntry = ttk.Entry(root, style="TEntry")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM