tkinter ttk widgets ignoring background color?

python, tkinter

Solution

I was having this problem as well, and I believe the issue is ttk's "aqua" theme, which is the default on OSX, doesn't respect background colour configuration in a number of widgets. I solved the problem by setting the theme to "default", which immediately caused all widgets' backgrounds to appear as specified.

Here's my basic example:

import tkinter
from tkinter import ttk

root = tkinter.Tk()
style = ttk.Style(root)
style.theme_use('classic')
style.configure('Test.TLabel', background= 'red')
text = ttk.Label(root, text= 'Hello', style= 'Test.TLabel')
text.grid()
root.mainloop()

Try changing `style.theme_use('classic')` to `style.theme_use('aqua')` to see the issue.

Problem

I'm using `tkinter`'s themed (`ttk`) GUI toolkit for an application. Trying to apply some uniform styling to the widgets in the main window: ``` s = ttk.Style() s.configure('.', background='#eeeeee') s.configure('.', font=('Helvetica', 14)) self.configure(background='#eeeeee') ``` The font change works great, but for some reason the widgets (i.e. `ttk.Label` and `ttk.Button`) don't seem to reflect the background change, which is pretty obvious visually due to contrast between the window's background and the widget's. If I check what it's set to: ``` label1.cget('background') ``` it returns `''`, so clearly it's not being set, but I don't understand what's wrong given the docs for ttk.Label and styles. Trying to set the background for a single label directly: ``` label1.configure(background='#eeeeee') ``` also doesn't work (i.e. no change). Any ideas?

Original source