Language - Python Windows IDLE: Difference between revisions

From Phidgets Support
No edit summary
(Redirected page to Language - Python)
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
[[Category:Language]]{{NoTitle}}{{Language_-_Python_Dev_Environment_Table}}
#REDIRECT [[Language - Python]]
{|
|style="vertical-align:middle; width: 60%;"|
<font size=6>'''Language - Python'''
 
'''Windows with IDLE'''</font>
 
Welcome to using Phidgets with Python! By using Python, you will have access to the complete Phidget22 API, including events.
 
IDLE is a cross-platform development environment for Python targeted at newcomers to the language.
 
|{{TOC limit|2}}
|}
 
<div style="text-size:24pt; color:red">WARNING: We do not recommend using IDLE with Phidgets. It has known problems dealing with multiple threads, which is a required feature if your program uses events.</div>
 
{{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}}
 
 
Right-click on the example and open it in IDLE:
[[Image:Python_idle_open.png|link=|center]]
 
 
To run the example, simply click on ''Run'' and select ''Run Module'':
[[Image:Python_idle_run.png|link=|center]]
 
Ensure that PhidgetHelperFunctions.py is in the same folder as the example.
 
{{Edit_the_Examples}}
 
{{Language_-_Python_Editing_The_Examples}}
 
==Setting Up a New Project==
When you are building a project from scratch, or adding Phidget functionality to an existing project, you'll need to configure your program to properly link the Phidget Python library.
 
To start, open Idle and create a new file:
[[Image:Python_idle_newfile.png|link=|center]]
 
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 Page What's Next}}

Latest revision as of 16:45, 15 March 2021

Redirect to: