Tkinter and IDE's
darnold02 at sprynet.com
Wed Nov 21 03:46:15 CET 2001
Here's the simple code I was trying to run (from 'Programming Python', 2nd
from Tkinter import *
print "Hello, I must be going"
# import sys
root = Tk()
widget = Button(root, text="Hello, event world", command = quit)
When I run it in IDLE, the tk window pops fine. Clicking the button once
outputs the message to the interactive window as expected, but doesn't
shutdown the tk window. Clicking the button a second time shuts down the tk
window, and IDLE along with it. I just found that if I delete(root) in the
interactive window before the 2nd click, the tk window closes and I raise a
NameError exception on 'root', but at least IDLE stays up and running.
If I replace root.quit() with sys.exit(), clicking on the button prompts me
with a dialog box that asks if I want to exit altogether. If I answer 'yes',
both the tk window and IDLE close (not too surprising). If I answer 'no',
the tk window remains up, this traceback is generated:
Traceback (most recent call last):
File "C:\Python21\mystuff\gui3.py", line 13, in ?
line 933, in mainloop
line 1290, in __call__
and the interactive window is responsive. Once again, clicking the button a
second time (without first deleting root) shuts down the whole shooting
Using either root.quit or sys.exit(), if I forego using my widget button to
exit and instead click on the Windows close button, the tk window closes,
but IDLE doesn't return to an interactive prompt and I can only exit it by
killing it via Task Manager. If I click on my widget button first, and then
Windows' close, the tk window closes and IDLE functions normally. I suppose
this is an okay workaround, but it isn't very pretty.
Sorry for being vague earlier.
Hope this helps,
On 20-Nov-2001, support @ internetdiscovery.com (Mike Clarkson) wrote:
> On Mon, 19 Nov 2001 16:54:51 -0800, "John Roth"
> <johnroth at ameritech.net> wrote:
> >"Don Arnold" <darnold02 at sprynet.com> wrote in message
> >news:9t9qsb$4nd$1 at slb3.atl.mindspring.net...
> >> I'm new to python and am interested in developing apps with Tkinter.
> >> However, every IDE I've come across for the Win32 platform experiences
> >> lockups/aborts when running Tkinter code. So far I've tried IDLE,
> >> and WING with little luck. Does anyone know of an IDE that
> >> executes Tkinter code?
> Don: Can you describe the lockups/aborts when using IDLE? Do you
> have a small test program that shows this? It would be very helpful.
> >There's a known problem with Tcl/tk that causes these lockups;
> John: he hasn't described the lockups enough to conclude that,
> nor has he said he's running in Win9x using Idle from a console
> window using python.exe instead of pythonw.exe (the default).
> That's a different problem, that is neither a lockup nor an abort.
> >at least, I assume it's with tcl/tk since it's been discussed
> >for quite a while, and the last time, someone said they had seen it in
> >a pure tcl/tk environment.
> If anyone said that they were wrong, because in any Tcl <= Tcl 8.3.4
> it is not even possible to load Tk into a running Windows console Tcl.
> There is no Tcl equivalent to 'import Tkinter' into a python.exe.
> >I suspect that the long term solution is going to be IBM's anygui
> If there are lockups and/or aborts using Idle to build Tkinter apps,
> they should be diagnosed and solved. It is possible that there is a
> problem in the C code for mainloop, and if so, you should be able to
> work around this by running your own mainloop in Python:
> self.done = -1
> while self.done < 0:
> where your self.quit() method sets self.done to 1.
More information about the Python-list