SelectionControls

Selection controls allow the user to select options.

https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/selection-controll.png

KivyMD provides the following selection controls classes for use:

MDCheckbox

from kivy.lang import Builder

from kivymd.app import MDApp


KV = '''
MDFloatLayout:

    MDCheckbox:
        size_hint: None, None
        size: "48dp", "48dp"
        pos_hint: {'center_x': .5, 'center_y': .5}
'''


class Test(MDApp):
    def build(self):
        return Builder.load_string(KV)


Test().run()
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/checkbox.gif

Note

Be sure to specify the size of the checkbox. By default, it is (dp(48), dp(48)), but the ripple effect takes up all the available space.

https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/checkbox-no-size.gif

Control state

MDCheckbox:
    on_active: app.on_checkbox_active(*args)
def on_checkbox_active(self, checkbox, value):
    if value:
        print('The checkbox', checkbox, 'is active', 'and', checkbox.state, 'state')
    else:
        print('The checkbox', checkbox, 'is inactive', 'and', checkbox.state, 'state')

MDCheckbox with group

from kivy.lang import Builder

from kivymd.app import MDApp

KV = '''
<Check@MDCheckbox>:
    group: 'group'
    size_hint: None, None
    size: dp(48), dp(48)


MDFloatLayout:

    Check:
        active: True
        pos_hint: {'center_x': .4, 'center_y': .5}

    Check:
        pos_hint: {'center_x': .6, 'center_y': .5}
'''


class Test(MDApp):
    def build(self):
        return Builder.load_string(KV)


Test().run()
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/checkbox-group.gif

MDSwitch

from kivy.lang import Builder

from kivymd.app import MDApp

KV = '''
MDFloatLayout:

    MDSwitch:
        pos_hint: {'center_x': .5, 'center_y': .5}
'''


class Test(MDApp):
    def build(self):
        return Builder.load_string(KV)


Test().run()
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/md-switch.gif

Note

For MDSwitch size is not required. By default it is (dp(36), dp(48)), but you can increase the width if you want.

MDSwitch:
    width: dp(64)
https://github.com/HeaTTheatR/KivyMD-data/raw/master/gallery/kivymddoc/md-switch_width.png

Note

Control state of MDSwitch same way as in MDCheckbox.

API - kivymd.uix.selectioncontrol.selectioncontrol

class kivymd.uix.selectioncontrol.selectioncontrol.MDCheckbox(**kwargs)

Class implements a circular ripple effect.

active

Indicates if the checkbox is active or inactive.

active is a BooleanProperty and defaults to False.

checkbox_icon_normal

Background icon of the checkbox used for the default graphical representation when the checkbox is not pressed.

checkbox_icon_normal is a StringProperty and defaults to ‘checkbox-blank-outline’.

checkbox_icon_down

Background icon of the checkbox used for the default graphical representation when the checkbox is pressed.

checkbox_icon_down is a StringProperty and defaults to ‘checkbox-marked’.

radio_icon_normal

Background icon (when using the group option) of the checkbox used for the default graphical representation when the checkbox is not pressed.

radio_icon_normal is a StringProperty and defaults to ‘checkbox-blank-circle-outline’.

radio_icon_down

Background icon (when using the group option) of the checkbox used for the default graphical representation when the checkbox is pressed.

radio_icon_down is a StringProperty and defaults to ‘checkbox-marked-circle’.

selected_color

Selected color in rgba format.

selected_color is a ColorProperty and defaults to None.

unselected_color

Unelected color in rgba format.

unselected_color is a ColorProperty and defaults to None.

disabled_color

Disabled color in rgba format.

disabled_color is a ColorProperty and defaults to None.

update_primary_color(self, instance, value)
update_icon(self, *args)
update_color(self, *args)
on_state(self, *args)
on_active(self, *args)
class kivymd.uix.selectioncontrol.selectioncontrol.MDSwitch(**kwargs)

This mixin class provides Button behavior. Please see the button behaviors module documentation for more information.

Events
on_press

Fired when the button is pressed.

on_release

Fired when the button is released (i.e. the touch/click that pressed the button goes away).

active

Indicates if the switch is active or inactive.

active is a BooleanProperty and defaults to False.

thumb_color

Get thumb color rgba format.

thumb_color is an AliasProperty and property is readonly.

thumb_color_disabled

Get thumb color disabled rgba format.

thumb_color_disabled is an AliasProperty and property is readonly.

thumb_color_down

Get thumb color down rgba format.

thumb_color_down is an AliasProperty and property is readonly.

theme_thumb_color

Thumb color scheme name

theme_thumb_color is an OptionProperty and defaults to Primary.

theme_thumb_down_color

Thumb Down color scheme name

theme_thumb_down_color is an OptionProperty and defaults to Primary.

on_size(self, *args)