在 kivy python 中 size_hint 的 属性 名称无效

Invalid property name for size_hint in kivy python

我正在做一个 kivy 教程 (FreeCodeCamp) 当我为我的按钮使用 size_hint 属性 时,它给出了 invlid 属性 name 的错误 代码: Python 文件:

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.widget import Widget


class BoxLayoutExample(BoxLayout):
    pass
    # def __init__(self, **kwargs):
    #     super().__init__(**kwargs)
    #     self.orientation = "vertical"  # There is also horizontal
    #     b1 = Button(text="Button 1")
    #     b2 = Button(text="Button 2")
    #     b3 = Button(text="Button 3")
    #     self.add_widget(b1)
    #     self.add_widget(b2)
    #     self.add_widget(b3)


class MainWidget(Widget):
    pass


class TheLabApp(App):
    pass


TheLabApp().run()

Kivy 文件:

BoxLayoutExample:


<BoxLayoutExample>:
    orientation: "vertical"
    Button:
        text: "A"
        size_hint = 1, .5
    Button:
        text: "B"
        size_hint = 1, 2
    Button:
        text: "C"
        size_hint = 1, 1

错误:

kivy.lang.parser.ParserException: Parser: File "kv file path", line 25:
 ...
      23:    Button:
      24:        text: "A"
 >>   25:        size_hint = 1, .5
      26:    Button:
      27:        text: "B"
 ...
 Invalid property name

同样的代码适用于提供教程的人。

尝试将 = 替换为 :,如下所示:

BoxLayoutExample:


<BoxLayoutExample>:
    orientation: "vertical"
    Button:
        text: "A"
        size_hint: 1, .5
    Button:
        text: "B"
        size_hint: 1, 2
    Button:
        text: "C"
        size_hint: 1, 1