The connection to the button is done with a perfboard from RadioShack. I like to use the ones with the square pads. It’s basically using the schematic from this Adafruit tutorial on using buttons with the Pi. It has a pullup resistor and a GPIO pin for each button you need. I just cut the ribbon cable from Adafruit to make the attachment to the Raspberry Pi. I only have one button wired in, but you could do more or even make LED indicator lights using the GPIO pins.
Button Shield using GPIO and Ribbon Cable
I wired in all the pins from the ribbon cable to the perfboard even though in this case I am only using a few. This was because in the future I may want to add additional buttons or use other pins. This setup means that the project can grow and I wouldn’t have to start from scratch.
NOTE: You can see that I actually have 2 pull-up resistors wired to pins 23 and 24, but I am only using GPIO pin 24 right now but pin 23 is ready for an additional button as is. I was thinking of adding the second button for taking a video but have not yet had a chance to add that feature.
Within Python, you can test to see if the button is pressed like this:
if(GPIO.input(24)==False):
This line of code looks to see if the GPIO pin 24 is currently grounded (i.e. pressed), The pull-up resistor prevents this pin from appearing grounded unless the button has been pressed.