[sf-lug] [PYCLASS] ThinkPython Chapter 19

a_kleider at yahoo.com a_kleider at yahoo.com
Mon Mar 23 18:54:04 PDT 2009

Asheesh, who has been facilitating a  weekly Python class based on the ThinkPython book by Allen Downey, has suggested that we post material pertaining to those classes on the list (which is where the idea of having the class was born.)

re attempt to follow the text at the beginning of chapter 19, why does the following code NOT show the button or the label as it should
and what's more, when the window is closed, the  error following the code is reported:

# To create a GUI: must import Gui and instantiate a Gui object:

from Gui import *

g = Gui()
g.mainloop()    # event loop: waits and responds

# A 'frame' has been created: a container for other widgets.

button = g.bu(text='Press me.') # a button widget
label = g.la(text='Press the button.')

# and here's the error report:
alex at ibmtp:~/Python$ python ex19.py
Traceback (most recent call last):
  File "ex19.py", line 16, in <module>
    button = g.bu(text='Press me.')    # a button widget
  File "/home/alex/Python/Gui.py", line 258, in bu
    return self.widget(Button, text=text, command=command, **options)
  File "/home/alex/Python/Gui.py", line 369, in widget
    widget = constructor(self.frame, **widopt)
  File "/usr/lib/python2.5/lib-tk/Tkinter.py", line 2013, in __init__
    Widget.__init__(self, master, 'button', cnf, kw)
  File "/usr/lib/python2.5/lib-tk/Tkinter.py", line 1943, in __init__
    (widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: can't invoke "button" command:  application has been destroyed
alex at ibmtp:~/Python$ 

a_kleider at yahoo.com


More information about the sf-lug mailing list