Tkinter causes hang

Tim Peters tim.one at home.com
Mon Apr 16 20:19:52 EDT 2001


[Stephen Ferg]
> I am running a Python program in a console window under
> Windows 95/98.  The program uses Tkinter.  When the program finishes,
> it hangs -- that is, I don't get the command-line prompt back again.

Join the club.  Tkinter does indeed hang at shutdown under Win9X at times,
and nobody has figured out why.  Fredrik Lundh was able to reproduce the
behavior with pure Tcl/Tk, so it's unlikely that it has anything to do with
Python.  At the times it hangs, it's *really* hung -- can't even break into
the process under a debugger then.

> ..
> To provide this kind of functionality, I am opening a "DOS box" (i.e.
> a console window) in Windows, and starting my Python program in the
> console window from the command-line prompt with the command:
>
>       python test1.py

The good news is that your problem will probably go away if you do

        pythonw test1.py

instead.  You'll find pythonw.exe in the same directory as your python.exe.
pythonw is a Windows-specific variant of the interpreter that, in effect,
doesn't try to *use* the DOS box for input or output.  Nobody knows why that
matters to Tk, but it does.

That's not why pythonw was invented, though, it's a lucky accident.  The real
point to pythonw is that if you double-click on a .pyw file, that executes
pythonw instead of python, and pythonw doesn't *create* a DOS box to run in.
That makes .pyw files the preferred way to, e.g., write Tkinter apps, or
Python services, or anything else where a DOS box isn't needed.






More information about the Python-list mailing list