Skip to main content

CTkSwitch

Example Code​

def switch_event():
print("switch toggled, current value:", switch_var.get())

switch_var = customtkinter.StringVar(value="on")
switch = customtkinter.CTkSwitch(app, text="CTkSwitch", command=switch_event,
variable=switch_var, onvalue="on", offvalue="off")
CTkSwitch example on macOS in dark mode

Arguments​

argumentvalue
mastermaster widget
widthwidth of complete widget in px
heightheight of complete widget in px
switch_widthwidth of switch in px
switch_heightheight of switch in px
corner_radiuscorner radius in px
border_widthbox border width in px
button_lengthlength of the switch button in px, 0 makes it round
bg_colorcolor behind the widget, only visible at the rounded corners, "transparent" (default) takes the color of the parent widget, tuple: (light_color, dark_color) or single color
fg_colorforeground (inside) color, tuple: (light_color, dark_color) or single color
border_colorborder color, tuple: (light_color, dark_color) or single color or "transparent" default is "transparent"
progress_colorcolor of switch when enabled, tuple: (light_color, dark_color) or single color or "transparent"
button_colorcolor of button, tuple: (light_color, dark_color) or single color
button_hover_colorhover color of button, tuple: (light_color, dark_color) or single color
text_colortext color, tuple: (light_color, dark_color) or single color
text_color_disabledtext color when disabled, tuple: (light_color, dark_color) or single color
textstring
textvariableTkinter StringVar to control the text
fontbutton text font, tuple: (font_name, size)
commandfunction will be called when the checkbox is clicked or .toggle() is called
variableTkinter variable to control or read checkbox state
onvaluestring or int for variable in checked state
offvaluestring or int for variable in unchecked state
hoverenable/disable hover effect: True, False
state"normal" (standard) or "disabled" (not clickable)

Arguments and methods that all widgets share, like bg_color, .bind(), .focus() or .destroy(), are described on Common arguments and methods.

Methods​

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

    All attributes can be configured and updated, for example:

    switch.configure(state="disabled")
  • .cget(attribute_name)​

    Pass attribute name as string and get current value of attribute.

  • .get()​

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

  • .set(state)​

    Switch on (True) or off (False), the command will not be triggered. (new in 6.0)

  • .select()​

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

  • .deselect()​

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

  • .toggle()​

    Flip current value of switch, command will be triggered.