Skip to content
Advertisement

why buttons not appear into widget in kivy python

i need to create a simple widget into a function then call the function from the inti function any help for me?

import kivy
from kivy.app import App
from kivy.uix.button import Label, Button
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder


class LoopButton(BoxLayout):
    
    def __init__(self, **kwargs):
        super(LoopButton , self).__init__(**kwargs)
        self.build()
        


    def build(self):

        layout = BoxLayout(orientation='vertical')
        btn1 = Button(text='Hello')
        btn2 = Button(text='World')
        layout.add_widget(btn1)
        layout.add_widget(btn2)
 
        return layout 

class TestApp(App):
    def build(self):
        return LoopButton()


if __name__ == '__main__':
    TestApp().run()

why my Buttons doesn’t appear

Advertisement

Answer

The Buttons are not appearing because you never add them to the App display. Just replace:

return layout 

with:

self.add_widget(layout)
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement