'why does python Kivy Boxlayout not show up when code is copied 100% from very recent tutorial?
i'm following a youtube tutorial on kivy and in the first part i already stumble upon a problem i can't seem to solve or find anything about: BoxLayout does not show up, like not even an error it just doesn't seem to exist even though i made sure the code was 100% the same as in the tutorial, please help.
Python file:
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
class BoxLayoutExample(BoxLayout):
pass
"""def __init__(self, **kwargs):
super().__init__(**kwargs)
self.orientation = "vertical"
b1 = Button(text="A")
b2 = Button(text="B")
b3 = Button(text="C")
self.add_widget(b1)
self.add_widget(b2)
self.add_widget(b3)
"""
class MainWidget(Widget):
pass
class TheLabApp(App):
pass
TheLabApp().run()`
KV File
MainWidget:
<BoxLayoutExample>:
orientation: "horizontal"
size: root.width, root.height
Button:
text: "A"
size_hint: .5, .5
pos_hint: { center_x: .5 }
color: 0, 0, 1, 1
Button:
text: "B"
Button:
text: "C"
<MainWidget>:
Button:
text: "Hello"
size: "100dp", "80dp"
pos: "100dp", "200dp"
color: 0, 0, 1, 1
Label:
text: "Hello2"
size: "100dp", "80dp"
pos: "200dp", "200dp"
color: 1, 0, 0, 1
Solution 1:[1]
the code looks a bit weird indentation wise, but probably your copy paste here, but did you name your kv file thelab.kv as required for it to be loaded automatically? (kivy looks for a kv file named like the app class, but lowercase, and without the "app" suffix).
Solution 2:[2]
Write BoxLayoutExample: at the top part of your kv file similar to how you wrote mainwidget: . After that it should work
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tshirtman |
| Solution 2 | snowdad23 |
