I am doing a kivy tutorial (FreeCodeCamp) When I use the size_hint property for my button, it gives an error for invlid property name Code: Python File:
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 File:
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
Error:
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
This same code works for the person giving the tutorial.
try to replace =
with :
like this:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.