Object-Oriented Programming in Python

Errata for Chapter 15

This errata is for the first printing (published 29 October 2007).


Note: Unfortunately the book went to print with software from this chapter that had been untested at the time. As a result, there were many minor and major errors in the displayed code. For this reason, we are providing a revised version of Chapter 15.


Page 498, Figure 15.3
Lines 6 and 10 should both read
self._textObj.setMessage(str(self._count))

Page 502, Figure 15.8
Line 8 should read
self._textObj.setMessage(self._textObj.getMessage() + event.getKey())
Line 10 should read
self._textObj.setMessage('')   # clear the text
To properly center the text on the canvas, line 13 should read
textDisplay = Text('', 12, Point(100,100)) # empty string initially

Page 503
In the second code block, the first line should read
class RotationHandler(EventHandler):
This remedies two problems. The class must inherit from EventHandler to operate as an event handler. Also, the name of the class must match the one used when constructing an instance in the third-to-last line.

Page 504, Figure 15.9
Line 6 should read
def handle(self, event):

Page 506, Figure 15.10
Line 7 should read
shape = event.getTrigger()
Line 39 should read
s.move(event.getMouseLocation().getX(), event.getMouseLocation().getY())
Line 44 should read
paper = Canvas(400, 300, 'white', 'Click me!')

Page 508, Figure 15.12
There are several errors. The popup canvas must be a member of the instance since it is accessed from within the display method. Also, the geometry is slightly off for centering the buttons. For completeness, you may download the revised version.

Page 510-512
There are several flaws with the Stopwatch implementation. The placement of the Text instances is errant, and the icons on the three buttons obscure the event handling associated with the buttons.

As a result, the second paragraph on page 510 should read as:
The complete implementation is given in Figure 15.14. Much of the constructor is dedicated to laying out the graphical components of the stopwatch, namely a border, a text display, three buttons, and appropriate icons. The display, the buttons and the icons are designated as data members so that we can reference them from the event handling routine. The border is identified with a local variable because we will not need to access it when handling an event. The loop at lines 28 and 29 is used to explicitly add all of our intended components to ourself (as a Layer).
The first line of the final paragraph on page 510 should have cited lines 43-59.

You may download the revised version of Figure 15.14.

Page 513
The last line says "pages 258-258 of Chapter 7" but should have read "pages 259-260 of Chapter 7".

Page 514-518
There are major changes to the MastermindGUI code and the surrounding prose. You may download the revised version of Figure 15.17.