[Tkinter-discuss] Waking up the Tk event loop from a thread
Kevin Walzer
kw at codebykevin.com
Wed Nov 6 23:52:47 CET 2013
Hello Guido,
On 11/6/13, 5:02 PM, Guido van Rossum wrote:
> Sadly, on Mac with Python 3 and Tcl/Tk 8.5 this exhibits exactly the
> problem I am complaining about -- the updates are erratic and often need
> to be helped along by moving the mouse or changing the focus.
You may be seeing an issue that's specific to recent versions of Tk on
the Mac.
In 2009, Apple sponsored a port of Tk from the Carbon API to the Cocoa
API because they had deprecated Carbon. The Cocoa port has many
advantages, not the least of which is better integration with various
system API's, but it has drawbacks as well. Specifically, the event loop
integration between Tk and Cocoa is complicated and fragile, much more
so than between Tk and Carbon (where the event loops were very similar
and easy to integrate).
This results in the kind of behavior you are seeing--sometimes there are
issues with event loop updates, window redraw, etc., and sometimes event
dispatching causes crashes.
My predecessor as maintainer of Tk on the Mac, Daniel Steffen, is the
author of the Cocoa port, but is now working for Apple and can't work on
Tk anymore. The result is that many of the event loop bugs must remain
unfixed--the code there is devilishly complex and, frankly, Daniel is
the only one who really understands it. I'm not even persuaded that the
impedance mismatch between the two event loops can be bridged, as Daniel
already did quite a bit of bug fixing and refinement of the event loop
stuff after the initial release of the Cocoa port.
In most cases I'm left recommending various workarounds for the
behavior, such as judicious use of update(), update_idlestasks(),
after(), and so on. Exercising the event loop by moving the mouse also
helps in some instances.
Hope that sheds some light on what you are seeing.
--Kevin
--
Kevin Walzer
Code by Kevin/Mobile Code by Kevin
http://www.codebykevin.com
http://www.wtmobilesoftware.com
More information about the Tkinter-discuss
mailing list