簡體   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