简体   繁体   English

如何在Kivy,python中创建Button的子类

[英]How to create a subclass of Button in Kivy, python

I have created a button subclass myButt using the method "@". 我使用方法“@”创建了一个按钮子类myButt。 But every time interpreter showing error. 但每次翻译都显示错误。 I am new to Kivy and have some basic knowledge of python. 我是Kivy的新手,对python有一些基本的了解。 Please help. 请帮忙。

<myButt@ToggleButton>:
    color: .8,.9,0,1
    font_size: 20
    background_color: 0,1,1,1
    group: 'a'

<simpleLayout>:
    padding: 10
    spacing: 10
    myButt:
        text: 'Hello'
        pos_hint: {'x': 0, 'y': 0}
        size_hint: 0.7, 0.5
    myButt:
        text: 'World!'
        pos_hint: {'top': 1, 'right': 1}
        size_hint: 0.3, 0.5

But it showing error: line 15 text: 'World!' 但它显示错误:第15行文字:'世界!' ^ SyntaxError: invalid syntax ^ SyntaxError:语法无效

Reason 原因

Dynamic class cannot start with lower case letter. 动态类不能以小写字母开头。

Solution

Replace myButt with MyButt myButt替换MyButt

Output 产量

结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM