I'm trying to create some buttons dynamically for Python and Kivy based on an external file.
So far, I managed to web scrape the file, read it and create widgets with it. The problem is that I need those widgets to have a unique var name and I can't see a way to achieve this.
def build(self):
#main layout
menu_box = BoxLayout(orientation="horizontal")
#web scraping
try:
WebLeida = request.urlopen("http://coznothingisforever.webs.com/Yoloplanner/Yoloplanner.txt").read().decode('utf8')
WebParsed = ast.literal_eval(WebLeida)
#for each item
for i in WebParsed:
#create a button
boton = Button(font_size=16,
size_hint_y=None,
height=100,
text=i["dia"] + " - " + i["hora"])
#bind the events
boton.bind(print("testing"))
#add the new created button to the layout
menu_box.add_widget(boton)
except:
print("Something went wrong")
#run the main layout
return menu_box
The problem with this is that all the buttons would be named "boton", so when I need to use specific functions like boton.bind the program won't know which one to use.
This is the desired outpost, but with unique var names:
Any suggestions?
Also, is web scraping the best way to achieve this?