This example show how to detect pressing on hardware button, then shutdown Raspberry Pi by calling os.system() to send command of "sudo shutdown -h now".
http://helloraspberrypi.blogspot.com/...
On this page of the site you can watch the video online Hardware button to shutdown Raspberry Pi, using Python with a duration of hours minute second in good quality, which was uploaded by the user an Erik 16 March 2015, share the link with friends and acquaintances, this video has already been watched 1,741 times on youtube and it was liked by 5 viewers. Enjoy your viewing!