There are a number of different ways to do this, some of it depends on how you have structured your code, and what you mean by print. If you just want to print the code the console, you could use on_active event. I put a small example below. IF you need more assistance please share a minimal, executable code.
from kivymd.app import MDApp
from kivy.lang import Builder
kv = """
MDBoxLayout:
MDCheckbox:
id: cb
size_hint_x: None
width: 48
on_active: print(f'Label Text: {label.text}; Checkbox is {self.active}')
MDLabel:
id: label
text: 'The text'
"""
class TestCheckBox(MDApp):
def build(self):
return Builder.load_string(kv)
TestCheckBox().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/bb3ee38e-dbb1-4268-9238-d8a73094b00dn%40googlegroups.com.
Code below. The key change is to the definition of <ItemConfirm> in kv.
The event on_active fires when the value of active changes. If active is true, meaning the box is checked then the text value associated with ItemConfrm (root.text) is printed.
The on_release event will fire if the line is clicked and released outside of the checkbox. We use it to change the state of the checkbox by setting or clearing the active attribute.
The use of root and self in kv is described here: https://kivy.org/doc/master/api-kivy.lang.html?highlight=lang#value-expressions-on-property-expressions-ids-and-reserved-keywords
from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.button import MDFlatButton
from kivymd.uix.dialog import MDDialog
from kivymd.uix.list import OneLineAvatarIconListItem
KV =
'''
<ItemConfirm>
on_release: check.active = not check.active
CheckboxLeftWidget:
id: check
group: "check"
on_active: if self.active: print(root.text)
MDFloatLayout:
MDFlatButton:
text: "ALERT DIALOG"
pos_hint: {'center_x': .5, 'center_y': .5}
on_release: app.show_confirmation_dialog()
'''
class ItemConfirm(OneLineAvatarIconListItem):
pass
# divider = None
#
# def set_icon(self, instance_check):
# instance_check.active = True
# check_list = instance_check.get_widgets(instance_check.group)
# for check in check_list:
# if check != instance_check:
# check.active = False
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/034f0be6-0499-4484-bec5-1bf282e10bb2n%40googlegroups.com.