|
|
(8 intermediate revisions by one other user not shown) |
Line 1: |
Line 1: |
| [[Category:Language]] | | #REDIRECT [[Language - Python]] |
| {{NoTitle}}
| |
| {{Language_-_Python_Dev_Environment_Table}}
| |
| {|
| |
| |style="vertical-align:middle; width: 60%;"|
| |
| <font size=6>'''Language - Python'''
| |
| | |
| '''Windows with Command Line'''</font>
| |
| | |
| Welcome to using Phidgets with Python! By using Python, you will have access to the complete Phidget22 API, including events.
| |
| | |
| The command line is the default environment to make Python programs in Windows, since it's available immediately after installing Python.
| |
| | |
| |{{TOC limit|2}}
| |
| |}
| |
| | |
| {{Language_-_Python_Intro_Windows}}
| |
| | |
| | |
| ==Use Our Examples==
| |
| One of the best ways to start programming with Phidgets is to use our example code as a guide. Before we get started, make sure you have read [[#Install Phidget Python module for Windows | how to install the Phidget Python module]] section above.
| |
| | |
| | |
| Now that you have Python and the Phidget Python module installed, select an example that will work with your Phidget:
| |
| *{{SampleCode|Python|Python Examples}}
| |
| | |
| | |
| Open the command prompt at the location of the example and enter the following command:
| |
| <syntaxhighlight lang=bash>
| |
| python example.py
| |
| </syntaxhighlight>
| |
| | |
| Ensure that PhidgetHelperFunctions.py is in the same folder as the example.
| |
| | |
| [[Image:Python_command_run.png|link=|center]]
| |
| | |
| {{Edit_the_Examples}}
| |
| | |
| {{Language_-_Python_Editing_The_Examples}}
| |
| | |
| {{Language_-_Python_Write_Code}}
| |
| | |
| ==Setting Up a New Script==
| |
| When you are building a script from scratch, or adding Phidget functionality to an existing script, you'll need to configure your program to properly link the Phidget Python library.
| |
| | |
| To include the Phidget Python library, add the following imports to your code:
| |
| | |
| <syntaxhighlight lang=python>
| |
| from Phidget22.PhidgetException import *
| |
| from Phidget22.Phidget import *
| |
| </syntaxhighlight>
| |
| | |
| Then, you will also have to import the class for your particular Phidget. For example, you would include the following line for a DigitalInput:
| |
| | |
| <syntaxhighlight lang=python>
| |
| from Phidget22.Devices.DigitalInput import *
| |
| </syntaxhighlight>
| |
| | |
| The script now has access to Phidgets.
| |
| | |
| {{Language_Further_Reading}}
| |