How to make ttk use OS theme?
I am using XFCE desktop environment and even the tk widgets do not adapt to the theme I use which is not so surprising because XFCE is based on GTK GUI Toolkit so there is no reason for a GTK theme to influence a Tk theme.
So you will need to change the theme of the GUI manually andthe only way to set the colors of ttk
widgets is through a ttk.Style
:
tk_bg = self.tk_label.cget("background")tk_fg = self.tk_label.cget("foreground")tk_entrybg = self.tk_entry.cget("background")style = ttk.Style(master)style.configure('TFrame', background=tk_bg)style.configure('TLabel', background=tk_bg, foreground=tk_fg)style.configure('TButton', background=tk_bg, foreground=tk_fg)style.configure('TEntry', background=tk_bg, fieldbackground=tk_entrybg, foreground=tk_fg)
All ttk widgets are associated to a style (usually 'T + widget name', except for the Treeview
for which there is no extra 'T'). And those styles are defined by the ttk theme you use. You can change theme with style.theme_use(<theme name>)
and you can get the available themes with style.theme_names()
.