Last active
September 5, 2015 20:03
-
-
Save nlowe/363703dc2ac0538ddc2b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kivy.app import App | |
from kivy.lang import Builder | |
from kivy.properties import ObjectProperty | |
from kivy.uix.label import Label | |
from kivy.uix.widget import Widget | |
UI = """ | |
#:kivy 1.9.0 | |
<ChildWidget>: | |
grid: grid_layout | |
GridLayout: | |
id: grid_layout | |
cols: 3 | |
<MainWindow>: | |
child: child | |
ChildWidget: | |
id: child | |
""" | |
class ChildWidget(Widget): | |
grid = ObjectProperty(None) | |
def __init__(self, **kwargs): | |
super().__init__(**kwargs) | |
self.grid.add_widget(Label(text="Test")) | |
# ^^^ | |
#Traceback (most recent call last): | |
# File "/home/nathan/projects/KivyTest/src/ssce.py", line 42, in <module> | |
# SSCE().run() | |
# File "/usr/lib/python3.4/site-packages/kivy/app.py", line 798, in run | |
# root = self.build() | |
# File "/home/nathan/projects/KivyTest/src/ssce.py", line 39, in build | |
# return MainWindow() | |
# File "/usr/lib/python3.4/site-packages/kivy/uix/widget.py", line 271, in __init__ | |
# Builder.apply(self) | |
# File "/usr/lib/python3.4/site-packages/kivy/lang.py", line 1872, in apply | |
# self._apply_rule(widget, rule, rule) | |
# File "/usr/lib/python3.4/site-packages/kivy/lang.py", line 1983, in _apply_rule | |
# child = cls(__no_builder=True) | |
# File "/home/nathan/projects/KivyTest/src/ssce.py", line 29, in __init__ | |
# self.grid.add_child(Label(text="Test")) | |
# AttributeError: 'NoneType' object has no attribute 'add_child' | |
class MainWindow(Widget): | |
child = ObjectProperty(None) | |
class SSCE(App): | |
def build(self): | |
Builder.load_string(UI) | |
return MainWindow() | |
if __name__ == '__main__': | |
SSCE().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From
#kivy
onirc.freenode.net
: