Straight from the Ministry of Silly Walks

Fredrik Lundh fredrik at pythonware.com
Mon Apr 16 11:33:56 EDT 2001


Brian & Colleen wrote:
> The following code is part of gui8.py from "Programming Python":
>
>     def quit(self):
>         ans = Dialog(self, title   = 'Verify quit',
>                            text    = 'Are you sure you want to quit?',
>                            bitmap  = 'question',
>                            default = 1,
>                            strings = ('Yes', 'No'))
>         if ans.num == 0:
>                   Frame.quit(self)
>
> It works (no surprise there -- the author knows his stuff).
>
> I paste the same piece of code into a very similar program and get a
> stack trace of:
>
> Exception in Tkinter callback
> Traceback (most recent call last):
>   File "/usr/local/lib/python2.0/lib-tk/Tkinter.py", line 1287, in
> __call__
>     return apply(self.func, args)
>   File "<stdin>", line 51, in quit
> AttributeError: 'Dialog' instance has no attribute 'num'

are you sure "Dialog" is the same thing in both cases?

try adding this to the top of that very similar program:

    import Dialog
    print Dialog.__file__

and compare the output with what you get if you type the
same commands at the interpreter prompt.

(you really want to use the tkMessageBox module instead, but
that's another story).

Cheers /F





More information about the Python-list mailing list