2015-01-16 31 views
0

我在寻找如何把按钮相同的属性,如CSS语言组...Kivy - 做一个类

我有了这个kivy文件:

<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' 
... 

我们能否得到这个代码优化?

感谢您的阅读。

回答

0

是的,你可以用dynamic classes轻松做到这一点!先从公共属性:

<[email protected]>: 
    size: root.width/10, root.width/10 

然后你可以用不同性质的完成:

MyButton: 
    text: 'A' 

MyButton: 
    text: 'Z' 
+0

它不工作,你可以给更多的代码吗?谢谢。 –