Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
711 views
in Technique[技术] by (71.8m points)

android - AttributeError: 'NoneType' object has no attribute 'current'

class LoginScreen(Screen):
    def __init__(self,**kwargs):
        super(LoginScreen, self).__init__(**kwargs)
        print self,self.parent.current

class AppScreenManager(ScreenManager):
    pass

#Base Class
class AppBaseClass(App):
    def build(self):
        icon='app_icon'
        return Builder.load_file('appbase.kv')


________________________________________________________________________________________________

AppScreenManager:
    transition: FadeTransition()
    LoginScreen:

Error: AttributeError: 'NoneType' object has no attribute 'current'. Please help.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

At the moment you call:

print self,self.parent.current

the LoginScreen is not instantiated yet, so you are calling for and object that does not exist.

The workaround is to delay the call by 1 frame, that can be done using Clock class:

 Clock.schedule_once(self._myprintfunction, 1/60)

and latter in your code but in the same class:

    def _myprintfunction(self, dt):
        print '-'*25
        print self
        print self.parent
        # print self.parent.curet <- this will throw you an error 
        print '-'*25

Hope it helps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...