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:
# 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):
    self._monitor = monitor

  def handle(self, event):
    if event.getDescription() == 'mouse click':

if __name__ == '__main__':
  paper = Canvas()
  checkpoint = Monitor()
  handler = ShapeHandler()

  cir = Circle(10, Point(50,50))
  square = Square(20, Point(25,75))



Recommended Answers

All 3 Replies

I assume you have the module calgraphics. The code example is written poorly and does not assign a namespace. Just hope that Monitor is a class from the module, see if you can find it in the module source code.

When you call/instantiante the class you should be including a monitor value. Someone on Chapter 15 of the book "Object-Oriented Programming in Python" should know how to call a class. Time to go back and review the basics.

@woooee, thanks for your answer. I tried with the monitor value and still didn't work! I was just curious though since I simply ran a program thats supposed to be credible and it wouldn't work.
Thanks @HiHe :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.