Overview

The package graphics.py is a simple object oriented graphics library designed to make it very easy for novice programmers to experiment with computer graphics in an object oriented fashion. It was written by John Zelle for use with the book “Python Programming: An Introduction to Computer Science” (Franklin, Beedle & Associates). The most recent version of the library can obtained at http://mcsp.wartburg.edu/zelle/python. This document is a reference to the functionality provided in the library. See the comments in the file for installation instructions.

There are two kinds of objects in the library. The GraphWin class implements a window where drawing can be done, and various graphics objects are provided that can be drawn into a GraphWin. As a simple example, here is a complete program to draw a circle of radius 10 centered in a 100x100 window:

from graphics import *

def main():
    win = GraphWin("My Circle", 100, 100)
    c = Circle(Point(50,50), 10)
    c.draw(win)
    win.getMouse() # pause for click in window
    win.close()

main()

GraphWin objects support coordinate transformation through the setCoords method and input via mouse or keyboard. The library provides the following graphical objects: Point, Line, Circle, Oval, Rectangle, Polygon, Text, Entry (for text-based input), and Image. Various attributes of graphical objects can be set such as outline-color, fill-color, and line-width. Graphical objects also support moving and undrawing for animation effects.