Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Background color of tkinter label will not change (python 3.4)

I am making a widget with Tkinter in python 3.4. For some reason, I cannot change a label's background color from the default grey. The code for the label is something like this:

self.label = ttk.Label(master, text="Label Text", 
                       foreground="blue", background="yellow")

Everything else works fine. I can change the foreground (text) color, however the background will not change, whether I am using label.config(), label['background'], or whatever.

I can change the background if I write it for Python 2.7, but I am using tutorials for Tkinter in 3.4, so this is undesirable.

like image 896
Justin Schulz Avatar asked Sep 14 '25 03:09

Justin Schulz


1 Answers

This bug is caused by the 'aqua' ttk style on Mac OSX. It also breaks 'ttk.Progressbar' when set to 'indeterminate' mode. To fix both issues insert the following code after 'root = Tk()' to change the style ...

style = ttk.Style()
style.theme_use('classic') # Any style other than aqua.

This solution was posted by dietrich41 here : http://www.python-forum.org/viewtopic.php?f=12&t=16212

I tested it on a Mac running Python 3.4.1.

like image 146
Inyoka Avatar answered Sep 17 '25 20:09

Inyoka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!