i need to create a simple widget into a function then call the function from the inti function any help for me?
JavaScript
x
33
33
1
import kivy
2
from kivy.app import App
3
from kivy.uix.button import Label, Button
4
from kivy.uix.boxlayout import BoxLayout
5
from kivy.lang import Builder
6
7
8
class LoopButton(BoxLayout):
9
10
def __init__(self, **kwargs):
11
super(LoopButton , self).__init__(**kwargs)
12
self.build()
13
14
15
16
def build(self):
17
18
layout = BoxLayout(orientation='vertical')
19
btn1 = Button(text='Hello')
20
btn2 = Button(text='World')
21
layout.add_widget(btn1)
22
layout.add_widget(btn2)
23
24
return layout
25
26
class TestApp(App):
27
def build(self):
28
return LoopButton()
29
30
31
if __name__ == '__main__':
32
TestApp().run()
33
why my Buttons doesn’t appear
Advertisement
Answer
The Buttons
are not appearing because you never add them to the App
display.
Just replace:
JavaScript
1
2
1
return layout
2
with:
JavaScript
1
2
1
self.add_widget(layout)
2