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.
self._textObj.setMessage(self._textObj.getMessage() + event.getKey())
self._textObj.setMessage('') # clear the text
textDisplay = Text('', 12, Point(100,100)) # empty string initially
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.
def handle(self, event):
shape = event.getTrigger()
paper = Canvas(400, 300, 'white', 'Click me!')
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.