Зелди
Зелди

Reputation: 86

Changing the background of tkinter checkbutton

I'm writing a program with a black background and white foreground. Everything ( Entries, labels, buttons ) work fine. But when I would make a checkbutton, I also would like to make it with black bg and white fg. I don't know why, but bg="black" doesn't change indicator background ( that little box you are clicking at ) to black. And I can't see the state of checkbutton.

checkbox is on, but I can't see it

Only when I move a cursor with pressed left button on it, I can see it states:

here

How can I fix this? Thanks.

Code of checkbutton:

self.encryptCheckButton = Checkbutton(self.root, text="Encrypt sended files?",
                                              variable=self.encryptFile,
                                              onvalue=1, offvalue=0,
                                              bg="black", fg="white",
                                              activebackground="black",
                                              activeforeground="white")

Upvotes: 2

Views: 2805

Answers (1)

10 Rep
10 Rep

Reputation: 2270

This is because, as @Saad says, the activeforeground parameter basically takes effect when the mouse hovers over the Checkbutton, not when you turn it on.

You need to use selecttcolor if you want the effect you desire. This will set it black when you select it.

Full code:

self.encryptCheckButton = Checkbutton(self.root, text="Encrypt sended files?",
                                              variable=self.encryptFile,
                                              onvalue=1, offvalue=0,
                                              bg="white", selectcolor = "black")

If this doesn't work for you, try this:

self.encryptCheckButton = Checkbutton(self.root, text="Encrypt sended files?",
                                              variable=self.encryptFile,
                                              onvalue=1, offvalue=0,
                                              bg="black", selectcolor = "white")

Hope this helps!

Upvotes: 1

Related Questions