kivy: “Invalid property name” error message for a valid property name

我的未来我决定 提交于 2019-12-12 04:46:38

问题


If I put this into the main program:

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

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


回答1:


You have a syntax error, try this:

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


来源:https://stackoverflow.com/questions/47236931/kivy-invalid-property-name-error-message-for-a-valid-property-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!