Here is an example:
from kivy.lang import Builder
from kivy.properties import StringProperty
from kivymd.app import MDApp
from kivymd.uix.list import IRightBodyTouch, OneLineAvatarIconListItem
from kivymd.uix.selectioncontrol import MDCheckbox
from kivymd.icon_definitions import md_icons
KV = '''
<ListItemWithCheckbox>:
IconLeftWidget:
icon: root.icon
RightCheckbox:
id: cb # crate an id to address the checkbox
MDBoxLayout:
orientation: 'vertical'
ScrollView:
MDList:
id: scroll
MDBoxLayout:
size_hint_y: None
height: dp(48)
Button:
text: 'Set CheckBoxes'
on_release: app.set_checkboxes(True)
Button:
text: 'Clear CheckBoxes'
on_release: app.set_checkboxes(False)
Button:
text: 'Set Item 5'
on_release: app.set_one_checkbox('Item 5', True)
'''
class ListItemWithCheckbox(OneLineAvatarIconListItem):
'''Custom list item.'''
icon = StringProperty("android")
class RightCheckbox(IRightBodyTouch, MDCheckbox):
'''Custom right container.'''
pass
class MainApp(MDApp):
def build(self):
return Builder.load_string(KV)
def on_start(self):
icons = list(md_icons.keys())
for i in range(30):
self.root.ids.scroll.add_widget(
ListItemWithCheckbox(text=f"Item {i}", icon=icons[i])
)
def set_checkboxes(self, v): # pass True to set, false to clear
# the children of scroll are the ListItemWithCheckBoxWidgets
for w in self.root.ids.scroll.children:
w.ids.cb.active = v
def set_one_checkbox(self, s, v):
# pass a string to identify a checkbox and value to set
for w in self.root.ids.scroll.children:
if w.text == s:
w.ids.cb.active = v
break
MainApp().run()
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/c913eff8-9082-42b2-ba2d-49500ef374fdn%40googlegroups.com.