Selection Controls¶
Selection controls allow the user to select options.
KivyMD provides the following selection controls classes for use:
MDCheckbox¶
from kivy.lang import Builder
from kivymd.app import MDApp
KV = '''
FloatLayout:
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()
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.
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)
FloatLayout:
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()
MDSwitch¶
from kivy.lang import Builder
from kivymd.app import MDApp
KV = '''
FloatLayout:
MDSwitch:
pos_hint: {'center_x': .5, 'center_y': .5}
'''
class Test(MDApp):
def build(self):
return Builder.load_string(KV)
Test().run()
Note
For MDCheckbox 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)
Note
Control state of MDSwitch same way as in
MDCheckbox.
API - kivymd.uix.selectioncontrol¶
-
class
kivymd.uix.selectioncontrol.MDCheckbox(**kwargs)¶ Bases:
kivymd.uix.behaviors.CircularRippleBehavior,kivy.uix.behaviors.ToggleButtonBehavior,kivymd.uix.label.MDIcon-
active¶ Indicates if the checkbox is active or inactive.
activeis aBooleanPropertyand 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_normalis aStringPropertyand 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_downis aStringPropertyand defaults to ‘checkbox-marked-outline’.
-
radio_icon_normal¶ Background icon (when using the
groupoption) of the checkbox used for the default graphical representation when the checkbox is not pressed.radio_icon_normalis aStringPropertyand defaults to ‘checkbox-blank-circle-outline’.
-
radio_icon_down¶ Background icon (when using the
groupoption) of the checkbox used for the default graphical representation when the checkbox is pressed.radio_icon_downis aStringPropertyand defaults to ‘checkbox-marked-circle-outline’.
-
selected_color¶ Selected color in
rgbaformat.selected_coloris aListPropertyand defaults to [].
-
unselected_color¶ Unelected color in
rgbaformat.unselected_coloris aListPropertyand defaults to [].
-
disabled_color¶ Disabled color in
rgbaformat.disabled_coloris aListPropertyand defaults to [].
-
update_icon(self, *args)¶
-
update_color(self, *args)¶
-
on_state(self, *args)¶
-
on_active(self, *args)¶
-
-
class
kivymd.uix.selectioncontrol.MDSwitch(**kwargs)¶ Bases:
kivymd.theming.ThemableBehavior,kivy.uix.behaviors.ButtonBehavior,kivy.uix.floatlayout.FloatLayout-
active¶ Indicates if the switch is active or inactive.
activeis aBooleanPropertyand defaults to False.
-
thumb_color¶ Get thumb color
rgbaformat.thumb_coloris anAliasPropertyand property is readonly.
-
thumb_color_disabled¶ Get thumb color disabled
rgbaformat.thumb_color_disabledis anAliasPropertyand property is readonly.
-
thumb_color_down¶ Get thumb color down
rgbaformat.thumb_color_downis anAliasPropertyand property is readonly.
-
on_size(self, *args)¶
-