so in my Tcl/Tk application I have a label with a text-variable:
label .mylabel -textvariable statustext -relief sunken -anchor w
and I can change the content of the label just fine by using something like set statustext "sponatenous error"
.
Unfortunately, sometimes the update of this variable is followed by some "heavy processing" that stalls the GUI for some time (e.g. downloading a file from the internet).
set statustext "downloading from $url"
download $url
Since the event-queue is blocked (at least, that's what I guess), the GUI does not get any refreshes and the label
does not show my latest message.
Is there a way to force-update the label text (preferrably via a textvariable) before starting my "heavy process"?
If you do update idletasks
before your heavy processing, the actual GUI update code will run. Tk works that way because actual GUI drawing is quite expensive and this allows it to bunch updates efficiently. It's a very clever piece of design that's made Tk GUIs seem super fast for over 25 years.
In some cases, a full update
is necessary — which can cause all sorts of problems with reentrancy of event handling — but updating a label can usually be done with the cheaper and less troublesome variant. That's especially true if your change doesn't alter the actual size of the label (which depends on how you're handling the geometry management of the whole containing toplevel, which is a huge topic). As a hint, it's usually best if your GUI doesn't resize itself when you alter a label's text dynamically; otherwise, that can be a bit disorienting to the user.