繁体   English   中英

kivy 中 size_hint 的无效属性名称 python

[英]Invalid property name for size_hint in kivy python

我正在做一个 kivy 教程 (FreeCodeCamp) 当我为我的按钮使用 size_hint 属性时,它给出了 invlid 属性名称错误代码: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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM