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")
CTkSegmentedButton example on macOS in dark mode

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)

Vertical orientation (new in 6.0):

segmented_button = customtkinter.CTkSegmentedButton(app, values=["Value 1", "Value 2", "Value 3"],
orientation="vertical")
Vertical CTkSegmentedButton on macOS in dark mode

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
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_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
background_corner_colorstuple of four colors for the background behind the corners (top left, top right, bottom right, bottom left), default is None
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
orientation"horizontal" (standard) or "vertical", stacks the buttons from top to bottom (new in 6.0)

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:

    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.

  • .index(value=None)​

    Returns the position of the selected value. If a value is passed, returns the position of that value instead. Raises ValueError if the value does not exist. (new in 6.0)

  • .len()​

    Returns the number of buttons. (new in 6.0)

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