[Pythonmac-SIG] Crash in MacPython 1.5.2c2 and Tk oddities

Bob Savage savageb@pacbell.net
Thu, 20 Apr 2000 09:23:35 -0700


on 4/19/00 4:14 PM, Russell E Owen wrote:
> Here is a sample script from Grayson's "Python and Tkinter". Note the
> use of root.quit (without the (); I'm not sure if that's optional or
> I had it wrong).

In this context the name root.quit is being assigned to a member element of
the button, not actually calling it; the button will 'add' the parentheses
itself, later on when it calls the function.

> I find that pushing the button neither closes the window nor quits
> anything. However, unlike some other things I've tried, I can
> actually quit using cmd-Q (twice, as usual, once for Tk, once for the
> interpreter) instead of having to force exit. An improvement.

Thank goodness for small favors :)

<code snipped>

Well that didn't work for me because I didn't have the "options" file, so I
tried this:

###################
# test of root.quit
from Tkinter import *

root = Tk()
root.title('Quit Me')
Button(root, text="What's gonna happen?", command=root.quit).pack()
root.mainloop()
# end of test code
##################

And when I clicked on the button everything quit quite nicely. I also tried
cmd-Q and got the same behavior you describe, that is, I needed to do either
cmd-Q twice or cmd-Q once and ctrl-D the second time. Incidentally, after
the first time a zero appears in the Python Out window, so I believe that
the first quit is terminating the TK/Wish process, which is in some way a
sub-process to the Python Interpreter (so it receives the exit code when the
Tkinter-based app terminates).

Not really sure where the problem is. Do you have "Keep stdio window open on
normal exit" checked?

I am starting to think that what you want to do to get rid of the double
quit is to bind that root.quit (once we figure out why it is working for me
but not for you) to both cmd-Q and to the menu option File:Quit. Then your
app will behave as expected.

Bob

BTW, thanks for pointing out that root.quit bit; I never ran across that
before. I might have to look into the Grayson book myself if it is full of
things like that.