This, of course, is not my code. It's from my object oriented programming course book. During class I ran the program and it worked a good 75% of the time without making any changes. For some reason, when I run it at home(either on python 2 or python 3) it won't work at all. I get error NameError: name 'Monitor' is not defined. Why is it doing that?
# Program: ShapeHandler.py
# Authors: Michael H. Goldwasser
# David Letscher
#
# This example is discussed in Chapter 15 of the book
# Object-Oriented Programming in Python
#
from cs1graphics import *
class ShapeHandler(EventHandler):
def __init__(self, monitor):
EventHandler.__init__(self)
self._monitor = monitor
def handle(self, event):
if event.getDescription() == 'mouse click':
self._monitor.release()
if __name__ == '__main__':
paper = Canvas()
checkpoint = Monitor()
handler = ShapeHandler()
cir = Circle(10, Point(50,50))
cir.setFillColor('blue')
cir.addHandler(handler)
paper.add(cir)
square = Square(20, Point(25,75))
square.setFillColor('red')
square.addHandler(handler)
paper.add(square)
checkpoint.wait()
paper.setBackgroundColor('green')
checkpoint.wait()
paper.setBackgroundColor('yellow')