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

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:

错误:AttributeError:'NoneType' 对象没有属性 'current'。请帮忙。

此时您拨打:

print self,self.parent.current

LoginScreen 尚未实例化,因此您正在调用不存在的对象。

解决方法是将调用延迟 1 帧,这可以使用 Clock class:

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

和后者在您的代码中但在相同的 class:

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

希望对您有所帮助。