Tkinter programming problem
Alex Martelli
aleax at aleax.it
Thu Aug 7 10:28:25 EDT 2003
klappnase wrote:
> "Mark Daley" <mark at diversiform.com> wrote in message
> news:<mailman.1060190417.25846.python-list at python.org>...
>> I have problems with sys.exit() when I'm running under IDLE, since it
>> seems
>> to cause ALL mainloops to exit, killing IDLE. I can't really give a
>> whole lot of detail on this, since I tend to use the command line to
>> launch my GUIs, anyway.
>>
> sys.exit()will stop (exit) the python interpreter. If you are running
> your program from within IDLE it will exit IDLE, too, because IDLE
> runs in the interpreter as well.
Depends on what release of IDLE you're running...:
> Python 2.3+ (#1, Aug 5 2003, 17:15:06)
> [GCC 3.2.2 (Mandrake Linux 9.1 3.2.2-3mdk)] on linux2
> Type "copyright", "credits" or "license()" for more information.
>
> ****************************************************************
> Personal firewall software may warn about the connection IDLE
> makes to its subprocess using this computer's internal loopback
> interface. This connection is not visible on any external
> interface and no data is sent to or received from the Internet.
> ****************************************************************
>
> IDLE 1.0
> >>> import sys
> >>> sys.exit(23)
>
> Traceback (most recent call last):
> File "<pyshell#1>", line 1, in -toplevel-
> sys.exit(23)
> SystemExit: 23
> >>>
As you see, with the IDLE 1.0 which comes with Python 2.3, the
exception raised by sys.exit is captured and displayed as such
[and similarly if sys.exit is called from a module run within
the IDLE session, rather than directly at the IDLE prompt].
(Why KNode only lets me "Paste as Quotation", not plain "Paste", what
I have "Select All" / "Copy" - ed from IDLE's PythonShell window,
is one of those mysteries which may need Poirot to unravel... mah...!).
> If you run your program from the command line sys.exit() will exit the
> interpreter and stop the program, of course any instructions in the
> code after sys.exit() won't be executed.
> I think normally that is exactly what I want in a gui program - stop
> everything if the main window is closed.
Often one may want to do some kind of clean-up at that point, but you
may achieve that with a try/finally around the mainloop call (putting
the cleanup code in the finally clause, of course).
> widget.destroy() will destroy "widget" and if "widget" is the main
> window of your application it will be destroyed - and all it's
> children with it.
> That's the way it should work if you are running from within the
> interpreter:
> your application is stopped but the interpreter won't be affected by
> this.
IDLE 1.0 agrees with you. However, the interactive text-mode Python
shell disagrees (it doesn't capture SystemExit and does terminate).
Alex
More information about the Python-list
mailing list