AddLocationForm:
<AddLocationForm@BoxLayout>:orientation:"vertical"
BoxLayout:
TextInput:
Button:
text: "Search"
Button:
text: "Current Location"
我有与上面类似的weather.kv 文件,但我收到如下错误
kivy.lang.parser.ParserException:解析器:文件“C:\programming\projects\scripts\kivy\FirstApp\weather.kv”,第3行:
谁能向我解释一下为什么会发生这种情况?
最佳答案
ParserException - 声明后数据无效
File "/usr/lib/python3/dist-packages/kivy/lang/parser.py", line 575, in parse_level
'Invalid data after declaration')
kivy.lang.parser.ParserException: Parser: File ".../weather.kv", line 3:
...
1:AddLocationForm:
2:
>> 3:<AddLocationForm@BoxLayout>:orientation:"vertical"
4: BoxLayout:
5: TextInput:
...
Invalid data after declaration
说明
您遇到以下ParserException,因为当您的kv文件被解析时,它在类规则声明之后不期望任何内容,
Programming Guide » Kv language » Rule context
A class rule, declared by the name of a widget class between < > and followed by :, defines how any instance of that class will be graphically represented:
解决方案
天气.kv
AddLocationForm:
<AddLocationForm@BoxLayout>
orientation: "vertical"
TextInput:
Button:
text: "Search"
Button:
text: "Current Location"
输出
关于python - Kivy中为什么会出现解析异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50080224/