Search code examples
pythontkintercolorswidgetttk

Python 2.7: How to change color of the ttk.Checkbutton label?


I want to change the color of the label of a ttk.Checkbutton widget.

From my understanding of the tkdocs I tought this code should work:

# -*- coding: utf-8 -*-                                                         

import ttk                                                                      
import Tkinter as tk                                                            

r = tk.Tk()                                                                     
s = ttk.Style()                                                                 
s.configure('Red.TCheckbutton.label', foreground='red')                         
cb = ttk.Checkbutton(master=r, style='Red.TCheckbutton', text='Test')           
cb.pack()                                                                       
r.mainloop()

But it produces a default black label.

What am I doing wrong?

Thanks Sebastian


Solution

  • You have an invalid style name. Replace:

    s.configure('Red.TCheckbutton.label', foreground='red')
    

    with:

    s.configure('Red.TCheckbutton', foreground='red')