Skip to content

CTkRadioButton

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

This CTkRadioButton works similar to the tkinter.Radiobutton.

Example Code:

Default theme:

radio_var = tkinter.IntVar(0)

def radiobutton_event():
    print("radiobutton toggled, current value:", radio_var.get())

radiobutton_1 = customtkinter.CTkRadioButton(master=root_tk, text="CTkRadioButton 1",
                                             command=radiobutton_event, variable= radio_var, value=1)
radiobutton_2 = customtkinter.CTkRadioButton(master=root_tk, text="CTkRadioButton 2",
                                             command=radiobutton_event, variable= radio_var, value=2)

radiobutton_1.pack(padx=20, pady=10)
radiobutton_2.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
radiobutton_width width of radiobutton in px
radiobutton_height height of radiobutton in px
corner_radius corner radius in px
border_width_unchecked border width in unchecked state in px
border_width_checked border width in checked state 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
value string or int value for variable when RadioButton is clicked

Methods:

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

    All attributes can be configured and updated.

    ctk_radiobutton.configure(fg_color=..., command=..., text=..., ...)
  • .select()

    Select radio button (set value to 1), command will not be triggered.

  • .deselect()

    Deselect radio button (set value to 0), command will not be triggered.

  • .invoke()

    Same action as if user would click the radio button, 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