I want to make a lot of Buttons at dynamic in kv language. But now I cannot...... I will show now source under this.
BoxLayout:
orientation: 'vertical'
pos: root.pos
size: root.size
GridLayout:
rows: 2
spacing: 5
padding: 5
Button:
text: "X0"
on_press: root.X(0)
Button:
text: "X1"
on_press: root.X(1)
I want to make like under code
BoxLayout:
orientation: 'vertical'
pos: root.pos
size: root.size
GridLayout:
rows: 2
spacing:5
padding:5
for i
Button:
text: "X#{i}"
on_press: root.X(i)
How can I do?
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:
I don't think this can be done in an
kv
file. However, if you can write the kv string in your python file, you can do something like this: