0

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.

Bloo
  • 3
  • 3
  • If you want to change the color of the entry field (the white part), then you need to use the style option `fieldbackground='black'`, not `background`. But I am not sure the default windows theme allows to change this color, you might have to use a different theme, e.g. 'clam'. – j_4321 Jan 31 '22 at 15:04
  • @j_4321 Thanks! Using a different theme worked. – Bloo Jan 31 '22 at 16:58

1 Answers1

0

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")
Mike Cash
  • 287
  • 4
  • 13
  • 1
    I believe you don't have to do that for default style names like TEntry. However if you create another name like name.TEntry then you have to apply it. – Bloo Jan 31 '22 at 14:55
  • You might be right, but is a good idea to have a custom style just in case you would want multiple entry widgets, you can also just use a Text widget and just change the background color in configure(), is there anything in particular that you would want to use an Entry widget over a Text widget? – Mike Cash Jan 31 '22 at 15:02
  • Not really, but I've made a lot of my program using Entry widgets and changing it all would be a pain. In the end, if I have to I might, however getting a solution to this would be nice. – Bloo Jan 31 '22 at 15:07