【问题标题】:Kivy - Make a classKivy - 上课
【发布时间】:2015-01-18 19:34:19
【问题描述】:

我正在寻找如何将按钮的相同属性放在像 css 语言这样的组中...

我有这个 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'
...

我们可以优化这段代码吗?

感谢阅读。

【问题讨论】:

    标签: python kivy


    【解决方案1】:

    是的,您可以使用dynamic classes 轻松做到这一点!从通用属性开始:

    <MyButton@Button>:
        size: root.width / 10, root.width / 10
    

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

    MyButton:
        text: 'A'
    
    MyButton:
        text: 'Z'
    

    【讨论】:

    • 它不起作用,你能提供更多代码吗?谢谢。
    猜你喜欢
    • 2018-04-30
    • 1970-01-01
    • 2021-04-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多