Skip to content

CTkSegmentedButton

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

Widget will be available with version 5.0.0!

Bildschirmfoto 2022-10-08 um 19 57 09

Example Code:

Without variable:

def segmented_button_callback(value):
    print("segmented button clicked:", value)

segemented_button = customtkinter.CTkSegmentedButton(master=app,
                                                     values=["Value 1", "Value 2", "Value 3"],
                                                     command=segmented_button_callback)
segemented_button.pack(padx=20, pady=10)
segemented_button.set("Value 1")  # set initial value

With variable:

segemented_button_var = customtkinter.StringVar(value="Value 1")  # set initial value

segemented_button = customtkinter.CTkSegmentedButton(master=app,
                                                     values=["Value 1", "Value 2", "Value 3"],
                                                     variable=segemented_button_var)
segemented_button.pack(padx=20, pady=10)

Arguments:

argument value
master root, frame, top-level
width box width in px
height box height in px
corner_radius corner radius in px
border_width space in px between buttons and the edges of the widget
fg_color color around the buttons, tuple: (light_color, dark_color) or single color
selected_color color of the selected button, tuple: (light_color, dark_color) or single color
selected_hover_color hover color of selected button, tuple: (light_color, dark_color) or single color
unselected_color color of the unselected buttons, tuple: (light_color, dark_color) or single color or "transparent"
unselected_hover_color hover color of unselected buttons, 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
font button text font, tuple: (font_name, size)
values list of string values for the buttons, can't be empty
variable StringVar to control the current selected value
state "normal" (standard) or "disabled" (not clickable, darker color)
command function will be called when the dropdown is clicked manually
dynamic_resizing enable/disable automatic resizing when text is too big to fit: True (standard), False

Methods:

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

    All attributes can be configured and updated.

    segemented_button.configure(state=..., command=..., values=[...], variable=..., ...)
  • .cget(attribute_name)

    Get values of all attributes specified as string.

  • .set(value)

    Set to specific value. If value is not in values list, no button will be selected.

  • .get()

    Get current string value.

  • .insert(index, value)

    Insert new value at given index into segmented button. Value will be also inserted into the values list.

  • .move(new_index, value)

    Move existing value to new index position.

  • .delete(value)

    Remove value from segmented button and values list. If value is currently selected, no button will be selected afterwards.

⚠️ Attention ⚠️

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

https://customtkinter.tomschimansky.com

Clone this wiki locally