이것을 메인 프로그램에 넣으면 :
class MyTextInput(TextInput):
def on_focus(self, *args, **kwargs):
print("Yay!", args, kwargs)
그리고 이것은 kv 파일에 :
#: import MyTextInput __main__.MyTextInput
MyTextInput:
id: e_birth_date
text: ""
size_hint_x: 1
그러면 동작이 정확합니다. 텍스트 입력이 포커스를 얻거나 잃을 때마다 인쇄됩니다.
Yay! (<__main__.MyTextInput object at 0x0CC1B8B8>, True) {}
Yay! (<__main__.MyTextInput object at 0x0CC1B8B8>, False) {}
그러나 이것은 전혀 작동하지 않습니다.
TextInput:
id: e_birth_date
text: ""
size_hint_x: 1
on_focus = root.on_field_focus(*args)
Kivy는 다음 메시지와 함께 .kv 파일 컴파일을 거부합니다.
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
왜? 이것은 버그입니까?
UPDATE : 다른 사람들이 쉽게 찾을 수 있도록 제목을 변경했습니다 (이는 특정 속성 이름과 관련이 없음).
구문 오류가 있습니다. 다음을 시도하십시오.
TextInput:
id: e_birth_date
text: ""
size_hint_x: 1
on_focus: root.on_field_focus(*args)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다