Novice in pyhton AND Raspberry prog, i want to create a Quizz-buzz Game. Up to 8 players can play it.
To catch the event when a button is pressed, (using the gpiozero lib) i want to do something like :
buttons = [Button(4), Button(5), Button(6), ....]
buttons.when_pressed = lambda : buttonpressed(buttons.buttonPressedIndex)
Rather than
button1 = Button(1)
button2 = Button(2)
button3 = Button(3)
....
button1.when_pressed = lambda : buttonpressed(1)
button2.when_pressed = lambda : buttonpressed(2)
....
Is it possible to do something like this ? How can i know which index of my array are trigger ?
Have a nice day
when_pressedinitialization to Button's constructor.buttons = [Button(i) for i in range(N)]and then set their
when_pressedfunction like that:for button in buttons: button.when_pressed = lambda: buttonpressed(button.buttonPressedIndex)