'For cycle to create items inside a MDList in kivy
please can U help me? I have an issue. There is a list called list_torn and this list is going to have several items when pressing a button from another screens.. this list got values of a textinput and a label and It will put it in this list(list_torn). The problem is that I'm trying to create a for cycle that can generate several OneLineListItems and there i want to put them inside of the MDList named "container1" that you can see it in the Kv.file.. Can U help me how to write the for cyce for generating the OneLineListItems inside the MDList?
main.py
#Add values to the list_torn located in the SecondWindow, "Buy"
def valores_tornillo(self):
tornillo= "tornillos"
number_tornillo= self.ids.input_tornillo.text
price_tornillo= self.ids.label_tornillo.text
result_tornillo= (f'{number_tornillo} {tornillo} cost: {price_tornillo}')
print(result_tornillo)
lista= self.manager.get_screen("Buy").list_torn
lista.append(result_tornillo)
class SecondWindow(Screen):
list_torn= []
md= ObjectProperty(None) #I need the MDList el id of container USar ObjectProperty()
def imprimir(self, list_torn):
print(list_torn)
for i in list_torn:
#print(i)
items= OneLineListItem(text= list_torn[i]+ "")
#self.root.ids.container1.add_widget(items)
md.add_widget(items) #IT's NOT WORKING HERE!
main.kv
<SecondWindow>:
name: "Buy"
md: container1
BoxLayout:
orientation: "vertical"
size: root.width, root.height
Label:
text: "Productos Añadidos"
font_size: 32
ScrollView:
MDList:
#I need add here OneLineListItem
id: container1
OneLineListItem:
id: item1
text: "Awesome List #1"
OneLineListItem:
id: item2
text: "Awesome List #2"
Button:
text:"press"
on_press: root.imprimir(root.list_torn)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
