Skip to main content

CTkSegmentedButton

Example Code

Without variable:

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

segemented_button = customtkinter.CTkSegmentedButton(app, values=["Value 1", "Value 2", "Value 3"],
command=segmented_button_callback)
segemented_button.set("Value 1")

With variable:

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

segemented_button_var = customtkinter.StringVar(value="Value 1")
segemented_button = customtkinter.CTkSegmentedButton(app, values=["Value 1", "Value 2", "Value 3"],
command=segmented_button_callback,
variable=segemented_button_var)

Arguments

argumentvalue
masterroot, frame, top-level
widthbox width in px
heightbox height in px
corner_radiuscorner radius in px
border_widthspace in px between buttons and the edges of the widget
fg_colorcolor around the buttons, tuple: (light_color, dark_color) or single color
selected_colorcolor of the selected button, tuple: (light_color, dark_color) or single color
selected_hover_colorhover color of selected button, tuple: (light_color, dark_color) or single color
unselected_colorcolor of the unselected buttons, tuple: (light_color, dark_color) or single color or "transparent"
unselected_hover_colorhover color of unselected buttons, 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
fontbutton text font, tuple: (font_name, size)
valueslist of string values for the buttons, can't be empty
variableStringVar to control the current selected value
state"normal" (standard) or "disabled" (not clickable, darker color)
commandfunction will be called when the dropdown is clicked manually
dynamic_resizingenable/disable automatic resizing when text is too big to fit: True (standard), False

Methods

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

    All attributes can be configured and updated, for example:

    segemented_button.configure(state="disabled")
  • .cget(attribute_name)

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

  • .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.