[R-gui] tcltk problem using "in"

Charilaos Skiadas cskiadas at gmail.com
Sat Dec 22 06:27:36 CET 2007


Replying to myself, though not sure that the threading will be  
preserved (long story short: I use gmail+pop, and as a consequence  
don't see my posts to the list, so I am responding to my sent message).

The problem is "explained" by the following code:

tktest <- function(parent) {
   fr <- tkframe(parent, borderwidth=2, relief="raised")      # Line 1
   l1 <- tklabel(parent, text="b")                           # Line 2
   l2 <- tklabel(fr,text="a")
   tkgrid(l1,l2, `in`=fr)
   fr
}

tt <- tktoplevel()
tf1 <- tktest(tt)
tkgrid(tf1)

The above code, as it stands, produces a nice frame with two letters,  
a and b, in it.
Now, if we interchange the lines I called Line 1 and Line 2 above,  
then in the resulting frame b doesn't show up any more, though there  
is space reserved for it.

In other words,  a widget cannot be inserted into a frame that was  
created after the widget came to existence (in which case we have to  
use the "in" argument). A quick check with code directly in Tcl/Tk  
seems to indicate that this is actually a limitation of Tcl/Tk  
(sounds to me a bit silly to have such limitation though).

Unfortunately, this makes what I was intending to do a lot more  
difficult. I was hoping to create "tkcbind" and "tkrbind" commands to  
allow one to build the GUI from the ground up. It sounds like I would  
need, at the very least, to specify beforehand the overall frame  
structure, and thus move top-to-bottom instead.

Is this problem documented anywhere?

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College



On Dec 21, 2007, at 7:38 PM, Charilaos Skiadas wrote:

> Hello all,
>
> 	I've been struggling for the best part of the last couple of hours  
> with the following simple problem. Consider the following code:
>
> library(tcltk)
> tktest <- function(parent, wdgt) {
>   fr <- tkframe(parent, borderwidth=2, relief="raised")
>   tkgrid(wdgt, `in`=fr)
>   tmp <- tklabel(fr, text="hi")
>   tmp2 <- tklabel(parent, text="there")
>   tkgrid(tmp)
>   tkgrid(tmp2, `in`=fr)
>   fr
> }
> tt <- tktoplevel()
> t2 <- tklabel(tt,text="a")
> t3 <- tklabel(tt,text="b")
> sg <- tktest(tt,t2)
> t4 <- tklabel(sg,text="c")
> tkgrid(t3,`in`=sg)
> tkgrid(t4)
> tkgrid(sg)
>
>
>
> Now, the resulting window contains the frame sg, with room in it  
> for all 5 strings a, hi, there, b, c,    BUT a and b are not showing!
> So, I am wondering what I am doing wrong. The `in` call seem to  
> work in one case, and fail in the other two cases, and I can't tell  
> what the difference is, especially between the "there" and "b"  
> cases. What I find more weird is that the space is allotted, but  
> not used.
>
> Any help appreciated, I am starting to lose my mind over here.
>
> Haris Skiadas
> Department of Mathematics and Computer Science
> Hanover College
>
>



More information about the R-SIG-GUI mailing list