Tk Source Code

View Ticket
Login
Ticket UUID: 220776
Title: update idletasks does not update repacked widgets on Windows
Type: Bug Version: obsolete: 8.0.3
Submitter: welch Created on: 2000-11-01 00:53:54
Subsystem: 69. Events Assigned To: aku
Priority: 6 Severity: Minor
Status: Open Last Modified: 2020-06-29 17:59:08
Resolution: None Closed By: nobody
    Closed on:
Description:
OriginalBugID: 674 Bug
Version: 8.0.3
SubmitDate: '1998-09-02'
LastModified: '2000-04-09'
Severity: LOW
Status: Assigned
Submitter: lfb
ChangedBy: hobbs
OS: All Windows
OSVersion: NA
Machine: NA
FixedInVersion: NA


button .foo -text "Hello World!"
pack .foo -expand yes
pack propagate . 0
. configure -width 200 -height 200
foreach anchor {center n ne e se s sw w nw center } {
    pack .foo -anchor $anchor

    # update the display
    update idletasks

    # wait half a sec
    after 500
}

Notice how the update idletasks does not remove the image of the button after it has been repacked.  Ick.



Reported on c.l.t by  [email protected] (John F. Davis)
(lfb)

This is a code fragment taken from Brent's book!
--
The work-around is to use 'update' instead of 'update idle'.
The problem is that the redraw of the of the button is
occurring within an idle callback, but evidently the redraw
of the underlying frame isn't.  Problem still in 8.2. 
-- 12/14/1999 hobbs
User Comments: chrstphrchvz added on 2020-06-29 17:59:08:

On macOS Aqua, the issue is absent possibly because idle redrawing currently relies on sending Expose events to any widgets intersecting with the area being redrawn, including portions of the container widget exposed when the contained widget moves. I'm not familiar enough with drawing on X11 to say why the issue doesn't happen there.


fvogel added on 2020-06-28 11:59:57:
I forgot to mention I have checked that this problem does not happen on Linux Debian 10 nor macOS Catalina (with core-8-6-branch as of 28 June 2020). Only Windows exhibits this issue.

fvogel added on 2020-06-27 17:47:17:

When running pack .foo -anchor $anchor, Tk_PackObjCmd()-->ConfigureSlaves() schedules ArrangePacking() to run at idle time.

When calling update idletasks, idle events are serviced, including the scheduled ArrangePacking(), which does all the needed geometry calculations and finally calls Tk_MoveResizeWindow().

Tk_MoveResizeWindow() then calls XMoveResizeWindow, which is an X11 function and is emulated on Windows (and macOS).

XMoveResizeWindow does the job through the Win API MoveWindow() function, with its last parameter to TRUE. The MSDN documentation for this function says the following about this parameter:

Indicates whether the window is to be repainted. If this parameter is TRUE, the window receives a message. If the parameter is FALSE, no repainting of any kind occurs. This applies to the client area, the nonclient area (including the title bar and scroll bars), and any part of the parent window uncovered as a result of moving a child window.

If I change this parameter to FALSE the provided test script makes the button move, but at the end of the script the frame is not repainted. So the documentation is correct. Moreover, this little test makes me conclude that repainting of the frame only happens after the script is finished: the frame repainting OS events do not appear to be serviced at idle time. Yeah, we already knew this.

Another data point: Adding TkDoConfigureNotify(winPtr->parentPtr); in Tk_MoveResizeWindow() aside of the already present TkDoConfigureNotify(winPtr); does not help.


chrstphrchvz added on 2020-06-26 02:40:42:

This issue still exists in 8.6.10.

pack/grid/place do not cause idle redrawing to be scheduled for the container, which would be needed to redraw newly exposed portions of the container when a contained widget moves or causes the container to resize. I think this is a bug, but in previous discussions of update idletasks it was deemed expected behavior for resizing to not trigger idle redrawing (so maybe it's expected behavior to not redraw the container even when it doesn't resize).

Should the behavior finally be deemed worth fixing, then I would think something like a ConfigureNotify or an Expose event needs to be sent to the container widget (a previously suggested workaound). Maybe any occurrences of TkDoConfigureNotify(winPtr) are missing TkDoConfigureNotify(winPtr->parent)—or even all the way up to the root window somehow.

Note that at least on recent versions of Windows, doing

update idletasks
after $ms
for long enough (about 5 seconds) causes Windows to think the program has stopped responding, preventing subsequent update idletasks; after $ms; from having any visible effect (my guess is the OS is expecting some sort of non-idle heartbeat/watchdog notifier or window manager event to be periodically handled). Of course the recommended approach is to use timer handlers instead, letting the Tcl event loop run and avoiding this issue altogether.


pcaffin added on 2008-03-13 15:48:21:
Logged In: YES 
user_id=2029956
Originator: NO

I've tested this with Tk 8.5.2.0.284581 (teapot) on both Debian Linux and Windows XP Pro.

I was unable to replicate the reported behaviour on Linux but it still occurs on Windows.

dkf added on 2004-04-06 16:10:11:
Logged In: YES 
user_id=79902

It looks like a subtle interaction between idle events and
window events, as if the events are necessary for the
correct redrawing of widgets taken from the OS toolkit.  The
only possible fix is to use [update] instead of [update
idletasks] and write the application so those extra events
don't cause bad things to happen.  The [grab] and [focus]
commands can help here.

IMO, this isn't a bug.  It's just life being tough.  It'd be
possible to add options to [update] to stop processing of
file events and timer events, but this is unlikely to help
because Tk uses timer events internally for quite a few
things, and many of the "bad" events are actually window
events that the programmer just doesn't want to deal with
right now.

jaspert added on 2004-04-05 19:30:10:
Logged In: YES 
user_id=456242

I have a problem which might be related to this (happens 
under WinXP but 98 and Unix are OK). An application doing 
a long calculation uses a message box and 'update idletasks' 
to keep the user informed of its progress. But if you raise 
another window, then the application's main window, the 
messages no longer get updated, giving the user the 
impression the application has hung.

vincentdarley added on 2002-08-28 19:49:54:
Logged In: YES 
user_id=32170

Problem still in 8.4b3.  Similar problem seems to occur 
on tkaqua (MacOS X), but I believe for different reasons.

vincentdarley added on 2002-07-02 22:55:05:
Logged In: YES 
user_id=32170

It would be good to fix this annoying behaviour before 
Tk 8.4 goes final.  "update" is sometimes not a good 
workaround, because all sorts of new events start to 
appear!

nobody added on 2001-09-28 02:45:40:
Logged In: NO 

Here's another simple manifestation of a similar problem:

>wish
label .l -bg red
frame .w -width 250 -height 20 -bg blue
pack .l -side left -fill none
pack .w -side right
update
pack propagate . 0
update
% repeat these lines to show the bug
.l configure -text "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
update
.l configure -text hi ; update idletasks ; after 1000

Occurs with Tk8.4a4 on Win2000sp2.  Lots of ugly 'AAAA' 
left behind when the label redraws.

This behaviour causes some unfortunate problems in some 
applications I use which need to display lots of messages 
to the user (in a 'status bar' type thing).  If the 
messages come too fast, garbage results, and 'update' is 
not a satisfactory solution...