Python/Kivy Assertion Error -
i obtained assertion error while attempting learn boxlayout in kivy. cannot figure out has went wrong.
kivy.app import app kivy.uix.button import button kivy.uix.boxlayout import boxlayout class boxlayoutapp(app): def build(self): return boxlayout() if __name__=="__main__": boxlayoutapp().run()
and kv code:
<boxlayout>: boxlayout: button: text: "test" button: text: "test" button: text: "test" boxlayout: button: text: "test" button: text: "test" button: text: "test"
edit: tried subclass boxlayout suggested however, still face assertionerror. full (original) error message reproduce here:
traceback (most recent call last): file "boxlayout.py", line 12, in <module> boxlayoutapp().run() file "c:\users\user\appdata\local\programs\python\python36-32\lib\site-packages\kivy\app.py", line 802, in run root = self.build() file "boxlayout.py", line 8, in build return boxlayout() file "c:\users\user\appdata\local\programs\python\python36-32\lib\site-packages\kivy\uix\boxlayout.py", line 131, in __init__ super(boxlayout, self).__init__(**kwargs) file "c:\users\user\appdata\local\programs\python\python36-32\lib\site-packages\kivy\uix\layout.py", line 76, in __in it__ super(layout, self).__init__(**kwargs) file "c:\users\user\appdata\local\programs\python\python36-32\lib\site-packages\kivy\uix\widget.py", line 345, in __i nit__ builder.apply(self, ignored_consts=self._kwargs_applied_init) file "c:\users\user\appdata\local\programs\python\python36-32\lib\site-packages\kivy\lang\builder.py", line 451, in pply self._apply_rule(widget, rule, rule, ignored_consts=ignored_consts) file "c:\users\user\appdata\local\programs\python\python36-32\lib\site-packages\kivy\lang\builder.py", line 566, in _ apply_rule self.apply(child) file "c:\users\user\appdata\local\programs\python\python36-32\lib\site-packages\kivy\lang\builder.py", line 451, in pply self._apply_rule(widget, rule, rule, ignored_consts=ignored_consts) file "c:\users\user\appdata\local\programs\python\python36-32\lib\site-packages\kivy\lang\builder.py", line 464, in _ apply_rule assert(rule not in self.rulectx) assertionerror
try subclassing boxlayout instead:
from kivy.app import app kivy.uix.button import button kivy.uix.boxlayout import boxlayout kivy.lang import builder class myboxlayout(boxlayout): pass builder.load_string(''' <myboxlayout>: boxlayout: button: text: "test" button: text: "test" button: text: "test" boxlayout: button: text: "test" button: text: "test" button: text: "test" ''') class boxlayoutapp(app): def build(self): return myboxlayout() if __name__=="__main__": boxlayoutapp().run()
the assertionerror
being thrown because try apply rules same class nesting.
in other words apply rule class, shall contain itself.
causes issues.
following throw same error.
<myboxlayout>: myboxlayout:
class boxlayoutapp(app):
ReplyDeleteuse the class name in capital I too have this problem when I put class name in small and used some words as a class name eg:layout like that
try this:
class Boxlayoutapp(app):
I hope this will help you.