1 回答
TA贡献1864条经验 获得超6个赞
是on_touch_down您可以绑定的事件,它不是MDCard您可以设置的属性。所以你可以像这样进行绑定:
def make_card(self):
for i in range(10):
card = MDCard(
orientation="vertical",
padding="8dp",
ripple_behavior=True,
size_hint=[1, None],
#on_touch_down = toast('clicked')
)
card.bind(on_touch_down=self.clicked) # set binding
label_link = MDLabel(text="Card" + str(i))
label_link.font_style = "Caption"
label_header = MDLabel(text="Title" + str(i))
label_header.size_hint = [1, 1]
card.add_widget(label_link)
card.add_widget(label_header)
self.sm.ids.first_screen_id.ids.first_screen_box_layout.add_widget(card)
# method called by binding
def clicked(self, card, touch):
if card.collide_point(*touch.pos):
print('clicked on', card.children[0].text)
添加回答
举报