I faced this problem: KeyError: 'city'. I get data from my database and put this data in dictionary. My code: Main.py
for row in rows:
city_dict = {'city': row[2]}
C = ClinicBanner(city=city_dict['city'])
result_banner.add_widget(C)
Clinicbanner.py
class ClinicBanner(GridLayout):
rows = 1
def __init__(self, city, **kwargs):
super(ClinicBanner, self).__init__(**kwargs)
centre = FloatLayout()
centre_button = Button(text=kwargs['city'], size_hint=(1, .8), pos_hint={"top": .2, "left": 1})
centre.add_widget(centre_button)
self.add_widget(centre)
And I got this error: line 14, in init centre_button = Button(text=kwargs['city'], size_hint=(1, .8), pos_hint={"top": .2, "left": 1}) KeyError: 'city'
I really hope that you can help me. Thank you for your answers!
You have defined the city argument in the init method:
def __init__(self, city, **kwargs):
Why do not use it:
centre_button = Button(text=city, size_hint=(1, .8), pos_hint={"top": .2, "left": 1})