Skip to content

CTkCheckBox

Tom Schimansky edited this page Dec 5, 2022 · 7 revisions

Example Code:

Default theme:

check_var = tkinter.StringVar("on")

def checkbox_event():
    print("checkbox toggled, current value:", check_var.get())

checkbox = customtkinter.CTkCheckBox(master=root_tk, text="CTkCheckBox", command=checkbox_event,
                                     variable=check_var, onvalue="on", offvalue="off")
checkbox.pack(padx=20, pady=10)

Arguments:

argument value
master root, tkinter.Frame or CTkFrame
width width of complete widget in px
height height of complete widget in px
checkbox_width width of checkbox in px
checkbox_height height of checkbox in px
corner_radius corner radius in px
border_width box border width in px
fg_color foreground (inside) color, tuple: (light_color, dark_color) or single color
border_color border color, tuple: (light_color, dark_color) or single color
hover_color hover color, tuple: (light_color, dark_color) or single color
text_color text color, tuple: (light_color, dark_color) or single color
text_color_disabled text color when disabled, tuple: (light_color, dark_color) or single color
text string
textvariable Tkinter StringVar to control the text
font button text font, tuple: (font_name, size)
hover enable/disable hover effect: True, False
state tkinter.NORMAL (standard) or tkinter.DISABLED (not clickable, darker color)
command function will be called when the checkbox is clicked
variable Tkinter variable to control or read checkbox state
onvalue string or int for variable in checked state
offvalue string or int for variable in unchecked state

Methods:

  • .configure(attribute=value, ...)

    All attributes can be configured and updated.

    ctk_checkbox.configure(fg_color=..., command=..., text=..., ...)
  • .get()

    Get current value, 1 or 0 (checked or not checked).

  • .select()

    Turn on checkbox (set value to 1), command will not be triggered.

  • .deselect()

    Turn off checkbox (set value to 0), command will not be triggered.

  • .toggle()

    Flip current value, command will be triggered.

⚠️ Attention ⚠️

The Github Wiki is outdated, the new documentation can be found at:

https://customtkinter.tomschimansky.com

Clone this wiki locally