From what I've read, this is a big no-no, but my current code is an eye sore, so I was hoping to lean on your expertise to see if there's a best practice way of initializing similar variables. Right now, this is how my code looks and seems ideal for a loop (for i in range(6)
):
If you think a loop would suffice for this, how do I make a variable name in that loop? I need to have them as a text name (I think) as opposed to storing it all in a dictionary for when I update these images in the kv
file. I say that because I don't know how to call a dictionary in the kv
file that is defined in the Python code. Any clever ideas?
WeatherForecastImage:
id: forecast_img_1
source: root.forecast_img_1
This is in the Python portion of my kivy build out:
forecast_img_1 = ObjectProperty(all_des.get(forecasts[1].text().lower()))
forecast_img_2 = ObjectProperty(all_des.get(forecasts[2].text().lower()))
forecast_img_3 = ObjectProperty(all_des.get(forecasts[3].text().lower()))
forecast_img_4 = ObjectProperty(all_des.get(forecasts[4].text().lower()))
forecast_img_5 = ObjectProperty(all_des.get(forecasts[5].text().lower()))