Additions to Zelle's Graphics for the Hands-on Python Tutorials
String Representations of all Graphics Object Types
Each graphical type can be converted to a string or printed, and a descriptive string is produced (for debugging purposes).
>>> pt = Point(30, 50)
>>> print pt
Point(30, 50)
>>> ln = Line(pt, Point(100, 150))
>>> print ln
Line: (30, 50)-(100, 150)
Asynchonous Detection of the Mouse
Two methods have been added to the Graphwin class for detecting the last mouse click
clearLastMouse()
Sets the last mouse position remembered to None. See getLastMouse() and the example below.
getLastMouse()
Returns the last mouse click point detected (or None if clearlastMouse() has been called since the last mouse click). This method is unlike getMouse(), in that it does not wait for a click. It returns the most recent click in the past, no matter what the program was doing at the time.
In the example below, the animation stops when the mouse has been clicked.
from graphics import *
import time
win = GraphWin()
circle = Circle(Point(100,100), 15)
circle.draw(win)
Text(Point(100, 40), "Click to quit.").draw(win)
win.clearLastMouse()
while win.getLastMouse() == None:
circle.move(50, 0)
time.sleep(.5)
circle.move(-50, 0)
time.sleep(.5)
win.close()