Pioneer_11
Pioneer_11

Reputation: 1265

tkinter set a different color for the tick and text in a checkbox

I'm trying to use checkboxes in tkinter. My GUI has a dark theme so I'd like to use white text on a dark background. Unfortunately if I do this by setting fg="white" bg="black" then I get a black background except for the box where the tick appears which remains white. This means that the tick is white on white background and therfore invisible.

Is there some way to either change the background of the box where the tick appears or, preferably, set the color of the tick mark independent of the rest of the text i.e. so I could have the check itself be a black tick on a white background while the rest of the widget consists of white text on a black background.

To illustrate the issue:

import tkinter as tk

root = tk.Tk()
var = tk.BooleanVar()
checkbutton = tk.Checkbutton(root, text="example", variable=var, bg="black", fg="white")
checkbutton.grid()
tk.mainloop()

Upvotes: 0

Views: 71

Answers (1)

Mukesh Choudhary
Mukesh Choudhary

Reputation: 24

import tkinter as tk

root = tk.Tk()
root.configure(bg="black")  # Set root background to black

var = tk.BooleanVar()
checkbutton = tk.Checkbutton(
    root,
    text="example",
    variable=var,
    fg="white",
    bg="black",
    activeforeground="white",
    activebackground="black",
    selectcolor="gray",  # Background color for the "checked" state
    indicatoron=False
)
checkbutton.grid(padx=20, pady=20)

root.mainloop()

Upvotes: -1

Related Questions