Next: GraphWin Objects
Up: Graphics Module Reference
Previous: Graphics Module Reference
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
GraphicsObjects 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 pointer-based input through
getMouse. 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
hiding for animation effects. An additional class, Pixmap, is provided
for simple image manipulation tasks.
Next: GraphWin Objects
Up: Graphics Module Reference
Previous: Graphics Module Reference
John Zelle
2006-09-04