试图引用带有变量的多个小部件。例如:
#.kv
Button:
id: button1
Button:
id: button2
Button:
id: button2
#.py
for x in range(3):
self.ids.button[x].text = "This is button " + x
答案 0 :(得分:0)
使用self.ids是dict(+ getattr stuff)这一事实可能是最简单的:
for x in range(3):
self.ids['button{}'.format(x)].text = 'This is button {}'.format(x)
您可能也可以使用getattr:
for x in range(3):
getattr(self.ids, 'button{}'.format(x)).text = 'This is button {}'.format(x)