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_pressed
initialization to Button's constructor.buttons = [Button(i) for i in range(N)]
when_pressed
function like that: for button in buttons: button.when_pressed = lambda: buttonpressed(button.buttonPressedIndex)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.