Doing a bit more research, I'm pretty sure my comment is correct.
The UI updates all widgets as needed every time through the event loop. Calling update
basically just forces it to run the event loop now. So, if you're in the middle of an event callback, you're recursively entering the event loop, which is a very bad thing, and can lead to infinite recursion.
As The TkInter Book says, update
:
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.
Similarly, the TkInter reference says:
This method forces the updating of the display. It should be used only if you know what you're doing, since it can lead to unpredictable behavior or looping. It should never be called from an event callback or a function that is called from an event callback.
Testing things out, it seems like at least in some cases, TkInter just ignores you when you call update
from inside the event loop. Presumably to protect you from infinite recursion, but I haven't looked at the code to verify that.
At any rate, this isn't the function you want, so it doesn't really matter why exactly it isn't doing what it wasn't documented to do.
If you need to trigger an update from within an event callback, call update_idletasks
. This actually calls all pending "idle" tasks, including redraws, without calling any event callbacks. (Not "update next time we're in the event loop and have nothing else to do".)
Meanwhile, calling raw_input
inside an event callback is even worse. You're blocking the main event loop on terminal input. Unless this was just something you did for debugging purposes, it's a very bad idea. And even for debugging purposes, it's a very odd thing to test, and it's entirely plausible that whatever happens will have no relevance to normal behavior.
For more background, see the question TkInter: How do widgets update, or search update_idletasks
on this site, or look at some of the Related links on the right side (at least two of which are relevant).
Based on your edit, as it turns out, it sounds like you had kind of the opposite problem—you were just changing things without telling TkInter to do anything about it, so the changes wouldn't show up until the next time through the event loop (which means not until after you return from this function). But the answer is basically the same—one way it's "replace your call to update
with update_idletasks
", the other way it's "add a call to update_idletasks
".