Such loops are not possible in kv, except to do some dirty hacks.
To create a set of buttons dynamically, use a ListView or add them to the loop inside the py file.
Example:
from functools import partial
class MyGrid(GridLayout):
def __init__(self, **kwargs):
super(MyGrid, self).__init__(**kwargs)
self.add_buttons()
def add_buttons(self):
for i in xrange(5):
button = Button(
text='X' + str(i),
on_press=partial(self.X, number=i)
)
self.add_widget(button)
def X(self, caller, number):
print caller, number
source
share