Reputation: 101
I'm searching how to put same properties of buttons in a group like the css language...
I've got this kivy file :
<Clavier>:
Button:
pos: 0, root.width / 5
size: root.width / 10 , root.width / 10
text: 'A'
Button:
y: root.width / 5
x: root.width / 10
size: root.width / 10 , root.width / 10
text: 'Z'
Button:
y: root.width / 5
x: root.width / 5
size: root.width / 10 , root.width / 10
text: 'E'
Button:
y: root.width / 5
x: root.width * 3 / 10
size: root.width / 10 , root.width / 10
text: 'R'
Button:
y: root.width / 5
x: root.width * 4 / 10
size: root.width / 10 , root.width / 10
text: 'T'
...
Can we get this code optimized ?
Thanks for reading.
Upvotes: 1
Views: 64
Reputation: 14794
Yes, you can do this easily with dynamic classes! Start with the common properties:
<MyButton@Button>:
size: root.width / 10, root.width / 10
Then you can finish with the differing properties:
MyButton:
text: 'A'
MyButton:
text: 'Z'
Upvotes: 1