Skip to content
Prev 9742 / 63424 Next

stuck tcltk scrollbars under Windows XP

Duncan Murdoch <dmurdoch@pair.com> writes:
We have an old issue on Windows which I haven't had the stamina to dig
into: On Unix, all Tcl event handling is keyed to the keyboard loop.
On Windows, we run a check for Tcl events "every once in a while".

I think it was Brian that implemented the Windows version and it
seemed like a good idea at the time. However, it breaks some things
where Tcl/Tk tends to assume atomic processing. E.g., this is behind
the code in the tkfaq demo (and elsewhere):

    txt <- tktext(tt, bg="white", font="courier")
    scr <- tkscrollbar(tt, repeatinterval=5,
                       command=function(...)tkyview(txt,...))
    ## Safest to make sure scr exists before setting yscrollcommand
    tkconfigure(txt, yscrollcommand=function(...)tkset(scr,...))

Where the point is that the text widget will otherwise generate an
event which results in a  call to tkset(scr,...), possibly before scr
exists.

In a Tcl script, there is no problem with this and the preferred idiom
is actually

text      .tt.txt -command {set .tt.scr} 
scrollbar .tt.scr -command {yview .tt.txt}

(although you can't run them like that individually on the wish
command line for the same reason as above).

I.e. Tcl scripts generally expect to run to completion before event
processing takes place. You could be bumping into something similar in
the function that calls tkgrab.