I'm trying to get a Screen
initialised with a number of Buttons
depending on the result from a query to my database but I'm getting an AttributeError
. I think this is because when I initialise my app there is no Information Screen
and reading this answer: AttributeError: 'NoneType' object has no attribute 'current'
I need to use Clock
to delay the initialisation of my Finder
class so my Information
class has time to be created but I'm not quite sure how I go about doing this in the __init__
method, or if this is even the right approach?
class Finder(Screen):
layout_profiles = ObjectProperty(None)
def __init__(self, **kwargs):
super(Finder, self).__init__(**kwargs)
self.mydb = mysql.connector.connect(host="localhost", user="root", passwd="", database="")
self.cur = self.mydb.cursor(buffered=True)
self.cur.execute("SELECT gender, age, name FROM users WHERE location = %s AND date_of_visit = %s",
(self.manager.get_screen('information').location.text,
self.manager.get_screen('information').date))
self.mydb.commit()
self.results = cur.fetchall()
self.cur.close()
self.mydb.close()
if self.results:
for result in self.results:
if result[0] == "male":
male_btn = MaleButton(text="{}, {}".format(result[1], result[2]))
self.layout_profiles.add_widget(male_btn)
elif result[0] == "female":
female_btn = FemaleButton(text="{}, {}".format(result[1], result[2]))
self.layout_profiles.add_widget(female_btn)
else:
unknown_btn = NoGenderButton(text="{}, {}".format(result[1], result[2]))
self.layout_profiles.add_widget(unknown_btn)
Error
line 249, in __init__
(self.manager.get_screen('information').location.text,
AttributeError: 'NoneType' object has no attribute 'get_screen'