AttributeError:'NoneType'对象没有属性'current' [英] AttributeError: 'NoneType' object has no attribute 'current'
本文介绍了AttributeError:'NoneType'对象没有属性'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'.请帮忙.
Error: AttributeError: 'NoneType' object has no attribute 'current'. Please help.
推荐答案
此刻您拨打电话:
print self,self.parent.current
LoginScreen尚未实例化,因此您正在调用和不存在的对象.
the LoginScreen is not instantiated yet, so you are calling for and object that does not exist.
解决方法是将呼叫延迟1帧,这可以使用Clock类完成:
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
希望有帮助.
这篇关于AttributeError:'NoneType'对象没有属性'current'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文