Dear all,

I have run into a small problem with a GUI that I have been writing in R using 
the tcltk package, and I was hoping that somebody on this forum may be able to 
shed some light on it for me. The problem that I have is that when the main 
function is called by a tkbutton() widget, the GUI window goes a bit funny; all 
non-widget areas turn see-through. On top of this, a counter that should be 
updating constantly will only update if the GUI window is moved. It appears 
that the window is not loading fully, so even though the counter is increasing 
correctly, it does not update on the window until you manually force it by 
moving it. 

However, if the function is called from the command line instead of linking it 
to a button press, everything works fine. This leads me to believe that the 
problem lies with the tkbutton(..., command=foo) command.

As an example, consider the following code:

tt <- tktoplevel()
frameOverall <- tkframe(tt)
counter <- tclVar("0")

## Top frame to contain counter
topFrame <- tkframe(frameOverall)
    progressLabel <- tklabel(topFrame, text=as.character(tclvalue(counter)))
    tkgrid(tklabel(topFrame, text="     "))
    tkgrid(progressLabel)
    tkgrid(tklabel(topFrame, text="     "))
tkgrid(topFrame)

## Function that makes the counter increase from 1 to 1000 when you press OK
foo <- function() {
    for (i in 1:1000) {
        counter <- tclVar(as.character(as.numeric(tclvalue(counter))+1))
        tkconfigure(progressLabel, textvariable=counter)
    }   
}

## Bottom frame to contain OK button
botFrame <- tkframe(frameOverall)
    tkgrid(tkbutton(botFrame, text="OK", command=foo))
tkgrid(botFrame)

tkgrid(frameOverall)

Pressing the button should cause the counter to increase. However the problem 
mentioned above occurs (move the window about to see the counter change. You 
may also see the window turn see-through). Now run the script again, but 
instead of pressing OK, run foo() manually in the command line. Everything 
works fine.

Is anybody able to tell me what is going wrong here? And more importantly, is 
there a way around it?

Many thanks for your assistance,

Sam Robson
MOAC Doctoral Training Center
Coventry House
University of Warwick
Coventry
CV4 7AL






        [[alternative HTML version deleted]]

_______________________________________________
R-SIG-GUI mailing list
R-SIG-GUI@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-gui

Reply via email to