Skip to content

Instantly share code, notes, and snippets.

@jmaicher
Created August 13, 2013 11:21
Show Gist options
  • Save jmaicher/6220192 to your computer and use it in GitHub Desktop.
Save jmaicher/6220192 to your computer and use it in GitHub Desktop.
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ObjectProperty
Builder.load_string('''
<MyContainer>:
MyWidget:
<MyWidget>:
my_button: my_button
Button:
id: my_button
''')
class MyContainer(BoxLayout):
pass
class MyWidget(Widget):
my_button = ObjectProperty()
def __init__(self, **kwargs):
super(MyWidget, self).__init__(**kwargs)
print "MyWidget#__init__ has been executed"
def on_my_button(self, *args):
print "MyWidget#my_button has been set"
class MyApp(App):
def build(self):
# return MyWidget()
return MyContainer()
MyApp().run()
@jmaicher
Copy link
Author

The answer I got in #kivy:

qua-non: kivy tries to delay the building of the gui of the widgets till they are actually needed. So the children inside a widget won't be set untill the next frame after super is called. When manually initializing a widget, properties can be initialised before the call to init/super

=> Yes, the behavior is expected!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment