![]() |
|
|
|||||||
![]() |
Python - newbie: why it does not work: command=sys.exit? |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
Posts: n/a
|
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 |
|
|
|
#2 |
|
Posts: n/a
|
-----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----- |
|
|
|
#3 |
|
Posts: n/a
|
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 |
|
![]() |
| Thread Tools | Search this Thread |
|
|
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 |