Download the Zelle graphics library: graphics.py. Put it in the same folder where you store your other Python documents. On a Macintosh, the default location is the folder Documents. On a PC, the default location is the folder C:\Python25. See Solutions to Common Problems below for more information about where Python looks for files.
Note that you should invoke the library by using the command
from graphics import *
instead of "import graphics".
Structure the file containing your program as follows:
from graphics import * # # Any other imports go here # def main(): # Open a drawing window. Specify your desired title, width, and height win = GraphWin(<title>, <width>, <height>) # # Your code goes here, using win as the drawing window # # Always end with waiting for a final mouseclick to close the window win.getMouse() win.close() # Now, run the main procedure main()
Save the file using a name that ends in "pyw", rather than "py". For example, save as "myprogram.pyw".
Select Run->Run Module to run your program. To run it again, type "main()" in the Shell window.
A console window may pop up when you run your program. You should be able to move it out of the way so you can see your graphics window. To keep it from appearing at all, try the following:
import mylibrary def main(): # Your code goes here # Now, run the main procedure main()
Solution: Use the IDLE menu option File->Open... to open any file that is in the same folder as your files (even an empty file). Select menu item Run->Run Module. In addition to restarting Python and loading the particular file, the internal list of places that Python uses to look for modules has now been expanded to include your folder. You can now import any of your files at the Python command prompt. Note that if you restart Python by Shell->Restart Shell in the shell window then the list of places that Python looks will be reset as well. If you edit a file that is in a different folder and select Run->Run Module, then the list of places is again reset and then expanded with the new folder.
Problem: That solution isn't good enough for me, I want to make Python look in several different folders for my files.
Solution: Download this module setpath.py. Open it in IDLE and select Run->Run Module. The list of places will be expanded to include "My Documents\python", "My Documents", "Documents", "Documents/python", and your top level home folder. You can edit this file so that it specifies any number of different folders.