<legend id='vCiBQ'><style id='vCiBQ'><dir id='vCiBQ'><q id='vCiBQ'></q></dir></style></legend>
<i id='vCiBQ'><tr id='vCiBQ'><dt id='vCiBQ'><q id='vCiBQ'><span id='vCiBQ'><b id='vCiBQ'><form id='vCiBQ'><ins id='vCiBQ'></ins><ul id='vCiBQ'></ul><sub id='vCiBQ'></sub></form><legend id='vCiBQ'></legend><bdo id='vCiBQ'><pre id='vCiBQ'><center id='vCiBQ'></center></pre></bdo></b><th id='vCiBQ'></th></span></q></dt></tr></i><div id='vCiBQ'><tfoot id='vCiBQ'></tfoot><dl id='vCiBQ'><fieldset id='vCiBQ'></fieldset></dl></div>
<tfoot id='vCiBQ'></tfoot>
    <bdo id='vCiBQ'></bdo><ul id='vCiBQ'></ul>

      <small id='vCiBQ'></small><noframes id='vCiBQ'>

        AttributeError: 'super' object has no attribute '

        AttributeError: #39;super#39; object has no attribute #39;__getattr__#39; Error when using BoxLayout with several kv-files in Kivy(AttributeError: super object has no attribute __getattr__ 在 Kivy 中使用带有多个 kv 文件的 BoxLayout 时出错)

            <tbody id='98IZ1'></tbody>
            <i id='98IZ1'><tr id='98IZ1'><dt id='98IZ1'><q id='98IZ1'><span id='98IZ1'><b id='98IZ1'><form id='98IZ1'><ins id='98IZ1'></ins><ul id='98IZ1'></ul><sub id='98IZ1'></sub></form><legend id='98IZ1'></legend><bdo id='98IZ1'><pre id='98IZ1'><center id='98IZ1'></center></pre></bdo></b><th id='98IZ1'></th></span></q></dt></tr></i><div id='98IZ1'><tfoot id='98IZ1'></tfoot><dl id='98IZ1'><fieldset id='98IZ1'></fieldset></dl></div>

              <bdo id='98IZ1'></bdo><ul id='98IZ1'></ul>
            • <small id='98IZ1'></small><noframes id='98IZ1'>

                <legend id='98IZ1'><style id='98IZ1'><dir id='98IZ1'><q id='98IZ1'></q></dir></style></legend>
                <tfoot id='98IZ1'></tfoot>

                  本文介绍了AttributeError: 'super' object has no attribute '__getattr__' 在 Kivy 中使用带有多个 kv 文件的 BoxLayout 时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我很清楚,这个问题已经被问过好几次了.但是在尝试了以下解决方案之后:

                  As I am very well aware, this question has been asked several times already. But after trying the following solutions:

                  • Python - Kivy: AttributeError: 'super'尝试获取 self.ids 时对象没有属性__getattr__"
                  • Python/Kivy AttributeError: 'super' object has no属性'__getattr__'
                  • 如何我可以在不获取 AttributeError 的情况下访问 kivy 中另一个类的对象属性吗:'super' object has no attribute '__getattr__'
                  • AttributeError: 'super' 对象没有属性 '__getattr__'

                  我已经得出结论,我需要帮助解决我的具体问题.列出的解决方案似乎不适用于我的具体情况.

                  I have reached the conclusion that i need help in my specific problem. The solutions listed didn't seem to work in my specific case.

                  以下情况:

                  我目前正在尝试使用 kivy 为智能手机开发应用程序.因为我喜欢我的代码非常干净和清晰的结构,所以我将我的 Kivy 代码拆分为几个 kv 文件.python 代码应该主要具有逻辑,仅此而已.为了让它正常工作,我需要在不同的 kv 文件中引用不同对象的实例.为了让我的问题更清楚,我构建了一个相当简单的例子:

                  I am currently trying to develop an application for smartphones using kivy. Since i like my code pretty clean and clear structured i have split my Kivy code into several kv-files. The python code is supposed to have primarily the logic and nothing more. In order to get it working properly i need to reference the instances of the different objects in the different kv-files. In order to make my problem clear i have constructed a fairly simple example:

                  文件:尝试.py

                  from kivy.app import App
                  from kivy.uix.widget import Widget
                  from kivy.factory import Factory
                  from kivy.uix.label import Label
                  from kivy.lang import Builder
                  
                  x= 1
                  
                  class ComplexBox(Widget):
                      def testit(self):
                          self.ids.layout.add_widget(Label(text = "Requirement A met."))
                      def addsome(self):
                          global x
                          self.ids.layout.add_widget(SomeWidget(id="XXX"+str(x)))
                          x = x +1
                      pass
                  
                  class SomeWidget(Widget):
                      def change(self):
                          self.ids.REQB.text = "Requirement B met."
                      pass
                  
                  class RequirementC(Widget):
                      def triggerC(self):
                          self.ids.ERRORBUTTON.text = "Requirement C met"
                      pass
                  
                  class Attempt(App):
                      def build(self):
                          return presentation
                      pass
                  
                  
                  presentation = Builder.load_file("attempt.kv")
                  Attempt().run()
                  

                  文件:尝试.kv

                  #:kivy 1.0
                  #:include attemptsupp.kv
                  #:include attemptsuppC.kv
                  
                  # root
                  <ComplexBox>:
                      BoxLayout:
                          id: layout
                          size: root.size
                          Button:
                              id: ERRORBUTTON
                              text: "add"
                              on_press: root.addsome()
                              on_release: root.testit()
                  BoxLayout:
                      orientation: 'vertical'
                      ComplexBox:
                      RequirementC:
                  

                  文件:attemptsupp.kv

                  FILE: attemptsupp.kv

                  #:kivy 1.0
                  
                  # rules for the widget
                  <SomeWidget>:
                      BoxLayout:
                          pos: root.pos
                          size: root.size
                          orientation: "vertical"
                          Label:
                              id: REQB
                              text: "hello"
                          Button:
                              text: "world"
                              on_release: root.change()
                  

                  文件:attemptsuppC.kv

                  FILE: attemptsuppC.kv

                  #:kivy 1.0
                  
                  <RequirementC>:
                      Button:
                          id: REQC
                          text: "Press"
                          on_release: root.triggerC()
                  

                  正在运行的程序的图片 - 按Press"- 按钮得到错误

                  使用 kivy 1.10 版和 Python 3.7.2 版运行,该程序首先可以正常启动.但是,当我按下标有按下"且 ID 为 ERRORBUTTON 的按钮时,出现此错误:

                  Running with kivy version 1.10 and Python version 3.7.2 the program first starts perfectly fine. But when I press on the Button labeled "press" with the id ERRORBUTTON I get this error:

                  ...--default --nodebug --client --host localhost --port 57777...attempt.py "
                  [INFO   ] [Logger      ] Record log in....kivylogskivy_19-03-15_31.txt
                  [INFO   ] [Kivy        ] v1.10.1
                  [INFO   ] [Python      ] v3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 
                  ...
                  [INFO   ] [Window      ] auto add sdl2 input provider
                  [INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
                  [WARNING] [Lang        ] attemptsupp.kv has already been included!
                  [WARNING] [Lang        ] attemptsuppC.kv has already been included!
                  [INFO   ] [Base        ] Start application main loop
                  [INFO   ] [GL          ] NPOT texture support is available
                  [INFO   ] [Base        ] Leaving application in progress...
                   Traceback (most recent call last):
                     File "kivyproperties.pyx", line 838, in kivy.properties.ObservableDict.__getattr__
                   KeyError: 'ERRORBUTTON'
                  
                   During handling of the above exception, another exception occurred:
                  
                   Traceback (most recent call last):
                     File "...ptvsd_launcher.py", line 45, in <module>
                       main(ptvsdArgs)
                     ...
                     File "e:DatenGithub_Projectspc-clickerattempt.py", line 35, in <module>
                       Attempt().run()
                     File "...libsite-packageskivyapp.py", line 826, in run
                       runTouchApp()
                  ...
                     File ...libsite-packageskivylanguilder.py", line 64, in custom_callback
                       exec(__kvlang__.co_value, idmap)
                     File ...attemptsuppC.kv", line 7, in <module>
                       on_release: root.triggerC()
                     File "...attempt.py", line 25, in triggerC
                       self.ids.ERRORBUTTON.text = "Requirement C met"
                     File "kivyproperties.pyx", line 841, in kivy.properties.ObservableDict.__getattr__
                   AttributeError: 'super' object has no attribute '__getattr__'
                  

                  即使我缩短了错误消息,也应该清楚发生了什么.在字典中找不到我在 RequirementC 类中引用的 ERRORBUTTON id.现在回答我的问题:

                  Even though I shortened the error message it should be clear what happens. The ERRORBUTTON id I am referencing in the RequirementC Class can't be found in the dictionary. Now to my question:

                  我怎样才能让它工作?我缺少什么?

                  How can i make it work? What am I a missing?

                  简而言之,我尝试了几件事:

                  Here in short a few things i have tried:

                  • 我尝试将 BoxLayouts 包装在 Screen 中并通过 screenmanager 访问它们.
                  • 我尝试在 python 代码中重新排列顺序.(例如先加载主kv文件)
                  • 我尝试过使用 Builder Factory 并在那里注册不同的类.
                  • 我已尝试更改参考.(例如 self.ids.['ERRORBUTTON']...)

                  这些尝试对我来说似乎都没有奏效.

                  None of these attempts seem to have worked in my case.

                  总结一下:

                  如何让不同类的 kivy 引用正常工作,为什么 ERRORBUTTON id 不在我正在查看的字典中?

                  How can I get my kivy References across different classes to work properly and why is the ERRORBUTTON id not in the dict I am looking into?

                  推荐答案

                  所以经过一番研究,我找到了我想要的答案.对于那些可能也会偶然发现我的问题的人来说:

                  So after a bit of research i found the answer i was looking for. For those who might also stumble over my problem here it comes:

                  class RequirementC(Widget):
                  def triggerC(self):
                      presentation.children[1].ids.ERRORBUTTON.text = "Requirement C met"
                  pass
                  

                  通过查看演示文稿的子项,可以使用ids"方法.

                  By going over the children of the presentation it is possible to use the "ids" method.

                  但对于那些想现在使用它的人,我建议遍历孩子以找到正确的 id,而不是给出硬"参考(孩子 [1]).

                  But for those tempted to use it now i would recommend iterating over the children to find the correct id instead of giving a "hard" reference (children[1]).

                  这篇关于AttributeError: 'super' object has no attribute '__getattr__' 在 Kivy 中使用带有多个 kv 文件的 BoxLayout 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Kivy 1.9.0 Windows package KeyError: #39;rthooks#39;(Kivy 1.9.0 Windows 包 KeyError: rthooks)
                  Python Kivy: how to call a function on button click?(Python Kivy:如何在按钮单击时调用函数?)
                  How to disable a widget in Kivy?(如何禁用 Kivy 中的小部件?)
                  Centering an object in Kivy(在 Kivy 中将对象居中)
                  How to downgrade to Python 3.4 from 3.5(如何从 Python 3.5 降级到 Python 3.4)
                  Change button or label text color in kivy(在kivy中更改按钮或标签文本颜色)

                      • <bdo id='U2vkc'></bdo><ul id='U2vkc'></ul>
                        <i id='U2vkc'><tr id='U2vkc'><dt id='U2vkc'><q id='U2vkc'><span id='U2vkc'><b id='U2vkc'><form id='U2vkc'><ins id='U2vkc'></ins><ul id='U2vkc'></ul><sub id='U2vkc'></sub></form><legend id='U2vkc'></legend><bdo id='U2vkc'><pre id='U2vkc'><center id='U2vkc'></center></pre></bdo></b><th id='U2vkc'></th></span></q></dt></tr></i><div id='U2vkc'><tfoot id='U2vkc'></tfoot><dl id='U2vkc'><fieldset id='U2vkc'></fieldset></dl></div>

                      • <legend id='U2vkc'><style id='U2vkc'><dir id='U2vkc'><q id='U2vkc'></q></dir></style></legend>

                        <small id='U2vkc'></small><noframes id='U2vkc'>

                          <tbody id='U2vkc'></tbody>

                        <tfoot id='U2vkc'></tfoot>