2

How can I code a OneLineListItem in KivyMD to print its "text" on a console? I came up with something like this:

[...]
item = OneLineListItem(text="DEMO", on_press= lambda x: ??????? )
list.add_widget(item)
[...]

I would like to have the word "DEMO" printed on the console after pressing on Item.

Bdyce
  • 332
  • 2
  • 11
bobk810i
  • 53
  • 6

1 Answers1

2

You can do it like below:

item = OneLineListItem(text="DEMO", on_press=lambda x: print(x.text))
amras
  • 1,499
  • 2
  • 6
  • 10
  • It is not working with multiple dynamicly created items. It always prints the last one text – bobk810i Aug 29 '20 at 15:29
  • Updated the answer. It should be ```print(x.text)``` and this will work for dynamically created items as well. – amras Aug 29 '20 at 16:38