2017-04-16 1 views
1

kivy에서 BoxLayout을 배우려고 시도하는 동안 어설 션 오류가 발생했습니다. 나는 무엇이 잘못되었는지 알 수 없다. Python/Kivy 어설 션 오류

from kivy.app import App 
    from kivy.uix.button import Button 
    from kivy.uix.boxlayout import BoxLayout 

    class BoxLayoutApp(App): 
     def build(self): 
      return BoxLayout() 


    if __name__=="__main__": 
     BoxLayoutApp().run() 

그리고 KV 코드

:

<BoxLayout>: 
    BoxLayout: 
     Button: 
      text: "test" 
     Button: 
      text: "test" 
     Button: 
      text: "test" 
    BoxLayout: 
     Button: 
      text: "test" 
     Button: 
      text: "test" 
     Button: 
      text: "test" 

편집 : 그러나 나는 아직도 AssertionError를 직면 제안 BoxLayout에서는 하위 클래스했습니다. 내가 여기에 재현 전체 (원본) 오류 메시지 대신

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 a 
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 a 
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 
+0

실제 오류를 보여주는 데 도움이됩니다. – Keith

답변

3

시도 서브 클래 싱 BoxLayout가 : 당신은 당신이 중첩되어 같은 클래스에 규칙을 적용하려고하기 때문에

from kivy.app import App 
from kivy.uix.button import Button 
from kivy.uix.boxlayout import BoxLayout 
from 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() 

AssertionError가 발생되고있다.
즉 규칙을 클래스에 적용하면 클래스 자체가 포함됩니다.
이로 인해 문제가 발생합니다.
다음과 같은 오류가 발생합니다.

<MyBoxLayout>: 
    MyBoxLayout: 
+0

오류를 수정해야하는 이유를 추가 할 수 있다면 좋을 것입니다. – syntonym

+0

@syntonym 업데이트 됨 – EL3PHANTEN