SegmentedControl#

New in version 1.0.0.

https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/segmented-control-preview.jpg

Usage#

from kivy.lang import Builder

from kivymd.app import MDApp


KV = '''
MDScreen:

    MDSegmentedControl:
        pos_hint: {"center_x": .5, "center_y": .5}

        MDSegmentedControlItem:
            text: "Male"

        MDSegmentedControlItem:
            text: "Female"

        MDSegmentedControlItem:
            text: "All"
'''


class Example(MDApp):
    def build(self):
        self.theme_cls.theme_style = "Dark"
        self.theme_cls.primary_palette = "Orange"
        return Builder.load_string(KV)


Example().run()
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/md-segmented-control-usage.gif

Events#

MDSegmentedControl:
    on_active: app.on_active(*args)
def on_active(
    self,
    segmented_control: MDSegmentedControl,
    segmented_item: MDSegmentedControlItem,
) -> None:
    '''Called when the segment is activated.'''

API - kivymd.uix.segmentedcontrol.segmentedcontrol#

class kivymd.uix.segmentedcontrol.segmentedcontrol.MDSegmentedControlItem(**kwargs)#

Implements a label to place on the SegmentPanel panel.

See MDLabel class documentation for more information.

class kivymd.uix.segmentedcontrol.segmentedcontrol.MDSegmentedControl(*args, **kwargs)#

Implements a segmented control panel.

Relative layout class. For more information, see in the RelativeLayout class documentation.

Events:
on_active

Called when the segment is activated.

md_bg_color#

Background color of the segment panel in (r, g, b, a) or string format.

MDSegmentedControl:
    md_bg_color: "brown"
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/md-segmented-control-md-bg-color.png

md_bg_color is an ColorProperty and defaults to [0, 0, 0, 0].

segment_color#

Color of the active segment in (r, g, b, a) or string format.

MDSegmentedControl:
    md_bg_color: "brown"
    segment_color: "red"
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/md-segmented-control-segment-color.png
MDSegmentedControl:
    md_bg_color: "brown"
    segment_color: "red"

    MDSegmentedControlItem:
        text: "[color=fff]Male[/color]"
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/md-segmented-control-text-color.png

segment_color is an ColorProperty and defaults to [0, 0, 0, 0].

segment_panel_height#

Height of the segment panel.

MDSegmentedControl:
    segment_panel_height: "56dp"
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/md-segmented-control-segment-panel-height.png

segment_panel_height is an NumericProperty and defaults to ‘42dp’.

separator_color#

The color of the separator between the segments in (r, g, b, a) or string format.

MDSegmentedControl:
    md_bg_color: "brown"
    segment_color: "red"
    separator_color: "white"
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/md-segmented-control-separator-color.png

separator_color is an ColorProperty and defaults to None.

radius#

Radius of the segment panel.

MDSegmentedControl:
    radius: 0
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/md-segmented-control-segment-radius.png

radius is an VariableListProperty and defaults to [16, 16, 16, 16].

segment_switching_transition#

Name of the animation type for the switch segment.

segment_switching_transition is a StringProperty and defaults to ‘in_cubic’.

segment_switching_duration#

Name of the animation type for the switch segment.

segment_switching_duration is a NumericProperty and defaults to 0.2.

current_active_segment#

The current active element of the MDSegmentedControlItem class.

current_active_segment is a ObjectProperty and defaults to None.

set_default_colors(self, *args)#

Sets the colors of the panel and the switch if the colors are not set by the user.

animation_segment_switch(self, widget: MDSegmentedControlItem)#

Animates the movement of the switch.

update_segment_panel_width(self, widget: MDSegmentedControlItem)#

Sets the width of the panel for the elements of the MDSegmentedControlItem class.

update_separator_color(self, widget: MDSeparator)#

Updates the color of the separators between segments.

add_widget(self, widget, *args, **kwargs)#

Add a new widget as a child of this widget.

Parameters:
widget: Widget

Widget to add to our list of children.

index: int, defaults to 0

Index to insert the widget in the list. Notice that the default of 0 means the widget is inserted at the beginning of the list and will thus be drawn on top of other sibling widgets. For a full discussion of the index and widget hierarchy, please see the Widgets Programming Guide.

New in version 1.0.5.

canvas: str, defaults to None

Canvas to add widget’s canvas to. Can be ‘before’, ‘after’ or None for the default canvas.

New in version 1.9.0.

>>> from kivy.uix.button import Button
>>> from kivy.uix.slider import Slider
>>> root = Widget()
>>> root.add_widget(Button())
>>> slider = Slider()
>>> root.add_widget(slider)
on_active(self, *args)#

Called when the segment is activated.

on_press_segment(self, widget: MDSegmentedControlItem, touch)#