[英]Attempting to create dynamic button class in Kivy in Python but getting invalid property name
I'm trying this out and I'm wondering why I'm not quite getting it. 我正在尝试,我想知道为什么我不太了解它。 I tried adding the code, but am getting:
我尝试添加代码,但得到:
Invalid property name on the line:
该行上的属性名称无效:
<MyButton@Button>:
Dynamic class declaration: 动态类声明:
<MyButton@Button>:
text: 'My Button!'
# .. other Button properties
So the entire bit of code is: 所以整个代码是:
<GridLayout>
cols: 4
row_default_height: 100
<MyButton@Button>:
text: 'My Button!'
# .. other Button properties
MyButton:
# properties I might want to set that aren't specified in dynamic class
Judging by your code I see these declarations: 从您的代码来看,我看到以下声明:
' <GridLayout>'
' <MyButton@Button>:'
If it's not just a formatting issue here on SO (Ctrl+K for propper formatting), then this will raise an error, because widget/rule declarations are only at the first level ( read: without any characters before <
, ' '
is a character too), which means the parser treats the declaration as a property probably because it contains :
character or maybe just because it's not at first level, which would mean that such string is either a property or a widget. 如果这不仅是SO上的格式问题(正确格式化为Ctrl + K),那么这将引发错误,因为窗口小部件/规则声明仅处于第一级( 读取:
<
, ' '
之前没有任何字符是字符),这意味着解析器将声明视为属性,可能是因为它包含:
字符,或者仅仅是因为它不在第一级,这意味着该字符串是属性或小部件。 (or a continuation of the previous line) (或上一行的延续)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.