I have spend the last few days making an app that I want to implement on a raspberry pi coupled to a 10 inch touchscreen. I am making this app for a student housing association here in Germany.
So the idea is to have the raspberry with the touchscreen installed on/next to/on top of (not sure yet), the common fridge. The fridge only holds drinks in .5L bottles format which cost 0.80€ to 1.10€ each. We don't pay immediately, we just write down our consummations on a list.
What I am trying to do is an app with the kivy library in which I can just click on my name, get a drink and the app would save my consumptions, what I already paid and save these infos in a CSV file. In order to do that I have to generate a number of buttons dynamically (the names of the poeple on the list) with kivy, which I did. But now it seems that I cannot assign them any function when they get pressed. More precisely, the index of each button doesn't seem to have any effect. I don't really know how to explain it so let's look at some code:
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
class grid(App):
button = [0 for i in range(25)]
def build(self):
main = GridLayout(cols = 5)
for i in range(25):
self.button[i] = Button(text = str(i))
self.button[i].bind(on_release =lambda x: grid.printString(str(i)))
main.add_widget(self.button[i])
return main
def printString(string):
print(string)
app = grid()
app.run()
So this isn't my actual code, it's an example that illustrates the problem. The output I get is 24 for each button I click. What I want is that each button prints it's own index in the button[] list. I have been trying to make this work for hours and I haven't found anything that worked. If anyone knows how to assign these button behaviors correctly, I would be really grateful for your input.