Go Back   Velocity Reviews > Newsgroups > Python
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


Reply

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

 
Thread Tools Search this Thread
Old 05-23-2004, 10:54 PM   #1
Paul van Dam
 
Posts: n/a
Default newbie: why it does not work: command=sys.exit?

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).
Exactly the same problem was raised by DrPhil:
http://coderforums.com/showthread.ph...oto=nextoldest

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


  Reply With Quote
Old 05-23-2004, 11:40 PM   #2
Kirk Strauser
 
Posts: n/a
Default Re: newbie: why it does not work: command=sys.exit?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

At 2004-05-23T22:54:53Z, "Paul van Dam" <> writes:
> import sys
> widget = Button(None, text='Hello widget world', command = sys.exit)



> 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


- From "pydoc sys.exit"

Help on built-in function exit in sys:

sys.exit = exit(...)
exit([status])

Exit the interpreter by raising SystemExit(status). If the status
is omitted or None, it defaults to zero (i.e., success). If the
status is numeric, it will be used as the system exit status. If it
is another kind of object, it will be printed and the system exit
status will be one (i.e., failure).

The documentation says that calling sys.exit raises a SystemExit exception.
Your program calls sys.exit and gets a SystemExit exception. It seems to be
working as expected and documented, unless I'm missing something.
- --
Kirk Strauser
The Strauser Group
Open. Solutions. Simple.
http://www.strausergroup.com/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFAsTXZ5sRg+Y0CpvERAthNAKCSCOtUsv/6eX4TU+ka0c93tOISrQCfRbRz
XvgGK2Kzu137pw4bNlWk7/k=
=mWAd
-----END PGP SIGNATURE-----
  Reply With Quote
Old 05-24-2004, 06:45 AM   #3
Alan Gauld
 
Posts: n/a
Default Re: newbie: why it does not work: command=sys.exit?

On Mon, 24 May 2004 00:54:53 +0200, "Paul van Dam"
<> 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
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Any help for maintaining the work flow of the system………. Zachar Software 1 08-04-2008 05:49 AM
Back button doesn't work when it is a secure page returning to a non secure page Miss Mary General Help Related Topics 1 09-21-2007 09:32 AM
Identity Theft at Work @ A True Review Silverstrand Front Page News 0 06-27-2006 02:56 PM
Rumor - Lucas has "subtly" altered the original Star Wars trilogy Modemac DVD Video 213 10-09-2004 01:43 AM
Re: Newbie: starting a small repair business... techshare A+ Certification 1 11-11-2003 11:14 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47