Such loops aren't possible in kv language, other than doing some dirty hacks.
To create a set of buttons dynamically, either use ListView or add them in a loop inside a 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
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…