[Tutor] Configuration?
Jeff Shannon
jeff@ccvcorp.com
Thu Mar 27 13:19:02 2003
Sison, Nick wrote:
>When running the GUI test session I get this right after I hit the exit
>button then python dies:
>
>When using IDLE I get this: [...]
>
>When using PythonWin I get this: [...]
>
>
I believe this problem isn't anything that you've done wrong. As it
turns out, both IDLE and PythonWin have a similar weakness -- they both
run scripts in the same process that they're running in, using the same
Python interpreter. This means that certain memory structures are
shared between the IDE and any scripts that you're running in them.
Normally this is not a problem, but it does tend to cause issues when
the scripts you're running use a GUI. Different GUI toolkits tend to
clash in ugly ways (thus PythonWin won't cooperate with Tkinter), and
even with the same GUI toolkit (IDLE uses Tkinter as well) only one
mainloop() is allowed per process, so trying to start a second
mainloop() from within IDLE causes problems.
There's several ways around this problem. The quickest is to simply
launch your GUI app from a command prompt. Open a command prompt window
(and run DOSKey if you're using Win9x!), cd to the directory that your
script is saved in, and run 'python myscript.py' -- your GUI should work
much better. You can make changes to the open window in IDLE/PythonWin,
save the changes, and just hit the up-arrow and return in your command
window to restart your script.
The other solution is to switch to a different IDE. Sourceforge has a
project called IDLEFork, which is an updated and upgraded version of
IDLE. (I think I've heard that IDLEFork will replace mainstream IDLE in
the Python 2.3 distribution, but I'm not certain about that.) One of
the improvements in IDLEFork is that it runs scripts in their own
process -- this means that you won't have the mainloop() clashes, and
your GUI script should work just fine. There's also a number of
commercial IDEs (such as WingIDE and, I think, Komodo) that run Python
scripts in a separate process, if you want to (and can afford to) go
that route.
Hope this helps!
Jeff Shannon
Technician/Programmer
Credit International