kivy:“无效的属性名称"有效属性名称的错误消息 [英] kivy: "Invalid property name" error message for a valid property name

查看:244
本文介绍了kivy:“无效的属性名称"有效属性名称的错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我将其放入主程序中:

If I put this into the main program:

class MyTextInput(TextInput):
    def on_focus(self, *args, **kwargs):
        print("Yay!", args, kwargs)

然后将其放入kv文件:

And this into the kv file:

#: import MyTextInput __main__.MyTextInput

                MyTextInput:
                    id: e_birth_date
                    text: ""
                    size_hint_x: 1

然后行为是正确的,只要文本输入获得焦点或失去焦点,就会打印此行为:

Then the behaviour is correct, this is printed whenever the text input gets or looses the focus:

Yay! (<__main__.MyTextInput object at 0x0CC1B8B8>, True) {} 
Yay! (<__main__.MyTextInput object at 0x0CC1B8B8>, False) {}

但是,这根本不起作用:

However, this does not work at all:

                TextInput:
                    id: e_birth_date
                    text: ""
                    size_hint_x: 1
                    on_focus = root.on_field_focus(*args)

Kivy拒绝使用以下消息编译.kv文件:

Kivy refuses to compile the .kv file with this message:

kivy.lang.parser.ParserException: Parser: File "C:\not_telling\app.kv", line 185:
 ...
     183:                        text: ""
     184:                        size_hint_x: 1
 >>  185:                        on_focus = root.on_field_focus(*args)
     186:                    TextInput:
     187:                        id: e_phone
 ...
 Invalid property name

为什么?这是一个错误吗?

Why? Is this a bug?

更新:更改了标题,以便其他人可以轻松找到它(事实证明,它与特定的属性名称无关).

UPDATE: Changed the title so that others can find this easily (as it turned out, it has nothing to do with that particular property name).

推荐答案

您遇到语法错误,请尝试以下操作:

You have a syntax error, try this:

TextInput:
    id: e_birth_date
    text: ""
    size_hint_x: 1
    on_focus: root.on_field_focus(*args)

这篇关于kivy:“无效的属性名称"有效属性名称的错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆