I am making an application.as far as I know I am doing thingd correctly but still getting this error
word=self.search_box.text AttributeError: \'NoneT
the problem is caused because the children are not stuck in the constructor of the parent, it does it an instant later so search_box will be None in the constructor, the solution is to execute it an instant after finishing the constructor with the help of Clock:
from kivy.clock import Clock
class DisplayPage(Screen):
search_box= ObjectProperty()
label_maening=StringProperty()
label_synonym=StringProperty()
label_ant=StringProperty()
label_sentence=StringProperty()
def __init__(self, **kwargs):
super(DisplayPage,self).__init__(**kwargs)
Clock.schedule_once(self.callback)
def callback(self, dt):
with open('vocab_words.json') as rfile:
data=json.load(rfile)
word=self.search_box.text #the error occurred here
for value in data:
if value['word']==word:
self.label_maening=value['meaning']
self.label_synonym=value['synonym']
self.label_ant=value['antonyms']
self.label_sentence=value['sentence']