0

I have stored highscores in a ListProperty() and I'm trying to fetch an item from that list by index inside kv file (code below). It keeps saying "list index out of range".

.py file:

scores = ListProperty()

.kv file:

Label:
    text: str(root.scores[1])

If I remove the [1] index part and just have str(root.scores) it perfectly shows the entire list.

1 Answers1

1

I just found an answer I think. When greating a new ListProperty() I have to know how big the list is in order to be able to access the items in kv using list indexed. So when I created the ListPropert as:

scores = ListProperty([['', 0], ['', 0], ['', 0], ['', 0]])

Then it worked perfectly in kv file.

I assume this goes with all the kivy properties, so that you have to know exact size of the property prehand.

  • 2
    You don't have to know the exact size of the property, just be aware that your kv rules may be applied with the default value you set. – inclement Jan 08 '15 at 14:32