From the effbot.org
documentation, we have the following about the update
function:
Processes all pending events, calls event callbacks, completes any
pending geometry management, redraws widgets as necessary, and calls
all pending idle tasks. This method should be used with care, since it
may lead to really nasty race conditions if called from the wrong
place (from within an event callback, for example, or from a function
that can in any way be called from an event callback, etc.). When in
doubt, use update_idletasks
instead.
On the other hand, there's this about the update_idletasks
function:
Calls all pending idle tasks, without processing any other events.
This can be used to carry out geometry management and redraw widgets
if necessary, without calling any callbacks.
As far as I understood, both call all pending idle tasks, complete any pending geometry management and redraw widgets as necessary. The only difference I see is that update
processes all pending events and calls event callbacks. That's why we should not call update
from within an even callback, I suppose.
However, I have seen examples where update_idletasks
and update
are used one after the other, and I can't understand the reason, since theoretically update
does everything update_idletasks
does.
What exactly are these pending events and the idle tasks the documentation is talking about? What are the differences and relations?
That being answered, in what real circumstances should I use update
over update_idletasks
? Concrete examples are also appreciated.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…