• <small id='PlKm3'></small><noframes id='PlKm3'>

  • <tfoot id='PlKm3'></tfoot>

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

      1. <legend id='PlKm3'><style id='PlKm3'><dir id='PlKm3'><q id='PlKm3'></q></dir></style></legend>

        Python/Kivy AttributeError:“超级"对象没有属性“

        时间:2023-10-10
      2. <legend id='7iqzS'><style id='7iqzS'><dir id='7iqzS'><q id='7iqzS'></q></dir></style></legend>
                <tbody id='7iqzS'></tbody>
              <tfoot id='7iqzS'></tfoot>
              <i id='7iqzS'><tr id='7iqzS'><dt id='7iqzS'><q id='7iqzS'><span id='7iqzS'><b id='7iqzS'><form id='7iqzS'><ins id='7iqzS'></ins><ul id='7iqzS'></ul><sub id='7iqzS'></sub></form><legend id='7iqzS'></legend><bdo id='7iqzS'><pre id='7iqzS'><center id='7iqzS'></center></pre></bdo></b><th id='7iqzS'></th></span></q></dt></tr></i><div id='7iqzS'><tfoot id='7iqzS'></tfoot><dl id='7iqzS'><fieldset id='7iqzS'></fieldset></dl></div>

                <bdo id='7iqzS'></bdo><ul id='7iqzS'></ul>

                  <small id='7iqzS'></small><noframes id='7iqzS'>

                  本文介绍了Python/Kivy AttributeError:“超级"对象没有属性“__getattr__"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我无法重新加载用户的图片或个人资料.我要重新加载的小部件包含在 ScreenOne 中,我在此类中创建了用于重新加载的函数,并尝试从 Change 类中的函数中调用它.

                  I am having trouble to reload picture or profile of user. The widget that I want to reload is included in the ScreenOne, I create the function for reloading in this class and try to call it from the function in the class Change.

                  提前谢谢你!

                  这是我的 main.py:

                  Here is my main.py:

                  from kivy.app import App
                  from kivy.uix.boxlayout import BoxLayout
                  from kivy.uix.image import Image
                  import readtable
                  import Readpictureadress
                  import sizetable
                  import Match
                  import nbofpictures
                  import random
                  from kivy.uix.screenmanager import ScreenManager, Screen, NoTransition
                  from kivy.properties import ObjectProperty, NumericProperty, StringProperty
                  import kivy
                  
                  
                  size = sizetable.main()
                  Iduserp = (random.randint(1, size))
                  imagenb=0
                  picadress= Readpictureadress.main(Iduserp, 0)
                  
                  class Manager(ScreenManager):
                  
                      screen_one = ObjectProperty(None)
                      screen_two = ObjectProperty(None)
                  
                  class ScreenTwo(Screen):
                      print('screentwo')
                      pass
                  
                  class ScreenOne(Screen):
                      img = StringProperty()
                      global picadress
                      global Iduserp
                  
                  
                      def __init__(self, **kwargs):
                          super(ScreenOne, self).__init__(**kwargs)
                          self.img = picadress
                  
                  
                      def displayScreenThenLeave(self):
                          print('Displayscreen')
                  
                          self.changeScreen()
                  
                      def changeScreen(self):
                          print('changescreen')
                  
                          if self.Manager.current == 'screen1':
                              self.Manager.current = 'screen2'
                          else:
                              self.Manager.current = 'screen1'
                      pass
                  
                      def reloadprofile(self):
                          self.img = picadress
                          self.ids.a1.reload()
                  
                  
                  class Change():
                      global Iduserp
                      global imagenb
                      global picadress
                  
                      def changeuser(self):
                  
                          size = sizetable.main()
                          Iduserp = (random.randint(1, size))
                          app = App.get_running_app()
                          app.screenone.reloadprofile()
                  
                      def changepicturenb (self):
                  
                          nbofpic = nbofpictures.main(Iduserp)
                          if imagenb < nbofpic:
                              imagenb += 1
                          else:
                              imagenb = 0
                          app = App.get_running_app()
                          app.screenone.reloadprofile()
                  
                  class ScreensApp(App):
                      print('ScreensApp')
                      screenone=ScreenOne()
                      varChange= Change()
                      def build(self):
                          m = Manager(transition=NoTransition())
                          return m
                  
                  if __name__ == "__main__":
                      ScreensApp().run()
                  

                  我的 kivy 文件:

                  My kivy file:

                  #:kivy 1.8.0
                  
                  <ScreenTwo>:
                  
                  <ScreenOne>:
                      stuff_a: a1
                      BoxLayout:
                          orientation: 'vertical'
                          rows: 4
                          BoxLayout:
                              orientation: 'vertical'
                              rows: 1
                              size_hint_y: 0.8
                              AsyncImage
                                  id:a1
                                  source:root.img
                                  on_touch_down: app.varChange.changepicturenb()
                  
                          BoxLayout:
                              padding: 10,10,10,0
                              spacing: 10
                              size_hint: 1,0.3
                              orientation: "horizontal"
                              Button:
                                  text: "Clear"
                                  on_touch_down: app.varChange.changeuser()
                              Button:
                                  text: "Remove"
                              Button:
                                  text: "Group"
                              Button:
                                  text: "Color"
                              Button:
                                  text: "Gestures"
                  
                  
                  <Manager>:
                      id: screen_manager
                  
                      screen_one: screen_one
                      screen_two: screen_two
                  
                      ScreenOne:
                          id: screen_one
                          name: "screen1"
                          manager: screen_manager
                  
                      ScreenTwo:
                          id: screen_two
                          name: "screen2"
                          manager: screen_manager
                  

                  还有我的错误文件:

                  > File "main7.py", line 105, in changeuser
                  >      app.screenone.reloadprofile()    File "main7.py", line 60, in reloadprofile
                  >      self.ids.a1.reload()    File "kivyproperties.pyx", line 839, in kivy.properties.ObservableDict.__getattr__ (kivyproperties.c:12654) 
                  > AttributeError: 'super' object has no attribute '__getattr__'
                  

                  推荐答案

                  正如@eyllanesc 所说:请提供一个最小、完整和可验证的示例.如果我们首先必须调试您的代码以达到我们可以看到您的问题的地步,那么我们需要做更多的工作才能弄清楚您的问题是什么.但是因为我有心情玩Kivy:

                  As @eyllanesc said: please provide a Minimal, Complete, and Verifiable example. It takes much more work for us to figure out what your problem is if we first must just debug your code to get to the point where we can see your problem. But since I am in the mood to play with Kivy:

                  你有几个问题.首先,更改您的 ScreensApp

                  You have several problems. First, change your ScreensApp

                  class ScreensApp(App):
                  
                      def build(self):
                          self.varChange = Change()
                          self.m = Manager(transition=NoTransition())
                          return self.m
                  

                  请注意,您创建的 ScreenOne 已被取消,因为它是由 kv 文件中的 <Manager> 规则创建的.其他语句被移动到 build 方法中并保存为实例变量,因为您在其他地方需要它们.这也允许您在 kv 文件中对 app.varChange 的引用起作用.

                  Note that your creation of a ScreenOne is eliminated, because that is created by your <Manager> rule in the kv file. The other statements are moved into the build method and saved as instance variables, since you need them elsewhere. This also allows your reference to app.varChange in your kv file to work.

                  另外,你需要修改你的 Change 类:

                  Also, you need to modify your Change class:

                  class Change():
                      global Iduserp
                      global imagenb
                      global picadress
                  
                      def changeuser(self):
                  
                          size = sizetable.main()
                          Iduserp = (random.randint(1, size))
                          app = App.get_running_app()
                          app.m.screen_one.reloadprofile()
                  
                      def changepicturenb (self):
                  
                          nbofpic = nbofpictures.main(Iduserp)
                          if imagenb < nbofpic:
                              imagenb += 1
                          else:
                              imagenb = 0
                          app = App.get_running_app()
                          app.m.screen_one.reloadprofile()
                  

                  ScreenOne 的引用作为 screen_one 保存在 kv 文件中的 <Manager> 规则中,因此要访问它,您可以通过 app 找到保存在 build<中的 m (Manager) 引用/code> 方法,然后是 <Manager> 规则中定义的 screen_one 属性.我认为这可能会解决您的问题,但我不能肯定,因为我必须对示例进行更改才能解决问题".

                  The reference to ScreenOne is saved in your <Manager> rule in the kv file as screen_one, so to access it you can go through the app, to the m (Manager) reference that was saved in the build method, and then to the screen_one property that was also defined in the <Manager> rule. I think that might fix your problem, but I can't be positive since I had to make changes to the example to get it to the "problem".

                  这篇关于Python/Kivy AttributeError:“超级"对象没有属性“__getattr__"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  <legend id='v6CBO'><style id='v6CBO'><dir id='v6CBO'><q id='v6CBO'></q></dir></style></legend>

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

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

                      • <tfoot id='v6CBO'></tfoot>

                          <bdo id='v6CBO'></bdo><ul id='v6CBO'></ul>
                            <tbody id='v6CBO'></tbody>