Python graphics Function
Python graphics
module can draw pictures. It is developed by John M. Zelle.
To install the module, you need to download the file graphics.py, and put it under the
Python library directory. For example, if Python is installed in "C:\python\", then put it under "C:\python\Lib\", or if Python is
installed in "/usr/bin/python/", then put it under "/usr/bin/python/Lib/".
To start drawing in Python, first create a drawing window:
>>> from graphics import * >>> w = GraphWin()
A window will appear on the screen, to continue draw a line:
>>> l = Line(Point(20,40),Point(50,40)) >>> l.draw(w)

Point:
>>> pt = point(30,50)#30, 50 are example coordinates >>> pt.draw(w)
Circle:
Circle(centerPoint, radius)
>>> cl = Circle(Point(40,50),3) >>> cl.draw(w)
Rectangle:
Rectangle(pt1,pt2)pt1, pt2 are the opposite corners of the rectangel.
Oval:
Oval(pt1,pt2)pt1, pt2 determine the bounding box of the oval.
Polygon:
Polygon(pt1,pt2,pt3,...)pt1,pt2,pt3 ... are the points of the polygon.
Draw Text:
Text(pt, str)pt is the anchor point, str is the string to be drawn.
After drawing, destroy the window by
w.close()
.
The other Python graphics library is Cairo, which can draw a image file.