Python/Kivy AttributeError: 'super' object has no attribute '__getattr__'

后端 未结 1 530
没有蜡笔的小新
没有蜡笔的小新 2021-01-29 07:59

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 t

1条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-29 08:08

    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:

    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
    

    Note that your creation of a ScreenOne is eliminated, because that is created by your 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.

    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()
    

    The reference to ScreenOne is saved in your 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 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".

    0 讨论(0)
提交回复
热议问题