python - Kivy中为什么会出现解析异常?

标签 python python-3.x user-interface kivy

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"

输出

enter image description here

关于python - Kivy中为什么会出现解析异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50080224/

相关文章:

python - Matplotlib 颜色条仅显示最多一半的刻度值

Linux Mint 上的 Python3 错误 "no module named bluetooth"

python - Argparse:如果子解析器共享父级,则子解析器的选项会覆盖主解析器

java - 在 JPanel 中绘图时未绘制任何内容

java - 帮助注释

JavaScript - 如何在不使用 alert() 或 window.open() 的情况下创建对话窗口?

python - 在Python中查找不等于不需要的字节的前一个字节

python - 在 Linux 中创建的 Python 应用程序的 Windows 安装程序

python-3.x - Python KafkaConsumer 从时间戳开始消费消息

python - 检查矩阵是否可以用 Jacobi 方法求解的代码不起作用