newbie: why it does not work: command=sys.exit?

Alan Gauld alan.gauld at btinternet.com
Mon May 24 02:45:36 EDT 2004


On Mon, 24 May 2004 00:54:53 +0200, "Paul van Dam"
<paul.van.dam at planet.nl> wrote:
> I have got a problem with een example from the book "Programming Python" -
> Mark Lutz
> I do not understand why it not work for Windows XP and Linux (Fedora Core
> 1.0).

> import sys
> from Tkinter import *
> widget = Button(None, text='Hello widget world', command = sys.exit)
> widget.pack()
> widget.mainloop()
> ----------------------------------------------------------------------------
> --------
> Traceback (most recent call last):
>   File "I:\Python\Projecten\#Prog_in_Python\Hfst06\gui02.py", line 5,
> in -toplevel-
>     widget.mainloop()
>   File "D:\Python23\lib\lib-tk\Tkinter.py", line 965, in mainloop
>     self.tk.mainloop(n)
>   File "D:\Python23\lib\lib-tk\Tkinter.py", line 1347, in __call__
>     raise SystemExit, msg
> SystemExit

It is working, its raising SystemExit. The environment that you
are running it in (Either Pythonwin or IDLE?) is catching
SystemExit and displaying the message rather than actually exit -
because it would be a pain having to restart IDLE everytime you
ran the program. But if you run your program from Explorer as
normal then it should exit just fine.

Remember that Pythonwin and IDLE are development tools they are
not the normal place to run programs. Because of that they
sometimes behave a little differently in an attempt to make life
easier for you while developing a program.

HTH,

Alan G
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld



More information about the Python-list mailing list