You will need to modify this a lot for your custom use case, but it can be a good place to get started
To use this package, you must install the C libraries for Phidgets:
http://www.phidgets.com/docs/OS_-_Linux
Then follow the instructions to install the Python Phidgets module: http://www.phidgets.com/docs/Language_-_Python