SegmentedControl#
New in version 1.0.0.
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()
from kivymd.app import MDApp
from kivymd.uix.screen import MDScreen
from kivymd.uix.segmentedcontrol import (
MDSegmentedControl, MDSegmentedControlItem
)
class Example(MDApp):
def build(self):
self.theme_cls.theme_style = "Dark"
self.theme_cls.primary_palette = "Orange"
return (
MDScreen(
MDSegmentedControl(
MDSegmentedControlItem(
text="Male"
),
MDSegmentedControlItem(
text="Female"
),
MDSegmentedControlItem(
text="All"
),
pos_hint={"center_x": 0.5, "center_y": 0.5}
)
)
)
Example().run()
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(*args, **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.
For more information, see in the
MDRelativeLayout
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"
md_bg_color
is anColorProperty
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"
MDSegmentedControl: md_bg_color: "brown" segment_color: "red" MDSegmentedControlItem: text: "[color=fff]Male[/color]"
segment_color
is anColorProperty
and defaults to [0, 0, 0, 0].
- segment_panel_height#
Height of the segment panel.
MDSegmentedControl: segment_panel_height: "56dp"
segment_panel_height
is anNumericProperty
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"
separator_color
is anColorProperty
and defaults to None.
- radius#
Radius of the segment panel.
MDSegmentedControl: radius: 0
radius
is anVariableListProperty
and defaults to [16, 16, 16, 16].
- segment_switching_transition#
Name of the animation type for the switch segment.
segment_switching_transition
is aStringProperty
and defaults to ‘in_cubic’.
- segment_switching_duration#
Name of the animation type for the switch segment.
segment_switching_duration
is aNumericProperty
and defaults to 0.2.
- current_active_segment#
The current active element of the
MDSegmentedControlItem
class.current_active_segment
is aObjectProperty
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.
- widget:
>>> 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)#