Reputation: 15000
I wrote this python code to dyanamically create a BoxLayout inside a screen.
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
class ListScreen(Screen):
def __init__(self,**kwargs):
super(ListScreen, self).__init__(**kwargs)
layout = BoxLayout(orientation ='vertical')
top_buttons=BoxLayout()
layout.add_widget(top_buttons)
top_buttons.add_widget(Button(text='Save'))
class ExampleApp(App):
def build(self):
root=ScreenManager()
root.add_widget(ListScreen(name='list'))
return root
ExampleApp().run()
It ran without any compilation error but the output is just a blank sreen.
Upvotes: 1
Views: 2854
Reputation: 4513
The problem is that you have not added layout
to the ListScreen
instance:
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
class ListScreen(Screen):
def __init__(self,**kwargs):
super(ListScreen, self).__init__(**kwargs)
layout = BoxLayout(orientation ='vertical')
self.add_widget(layout) #<<<<<<<<<<<<<<<<<
top_buttons=BoxLayout()
layout.add_widget(top_buttons)
layout.add_widget(Button(text='Save'))
class ExampleApp(App):
def build(self):
root=ListScreen()
root.add_widget(ListScreen(name='list'))
return root
ExampleApp().run()
Upvotes: 4