[R] Tk grid problem
j verzani
jverzani at gmail.com
Mon Jul 16 17:26:01 CEST 2012
vincent guyader <vincent.guyader <at> gmail.com> writes:
>
> Hi everybody,
>
> I have a problem with the grid function in tk.
> I juste try to put 4 buttons like this:
>
> -------------------
> | | |
> | | C |
> | A |--------|
> | | |
> ---------- D |
> | | |
> | B | |
> -------------------
>
> A is 2x2
> C is 1x2
> B is 1x2
> D is 2x2
>
> but the code bellow dont work :
>
> require(tcltk)
> tt <- tktoplevel(borderwidth=10)
>
> A.but <- tkbutton(tt,text="A",command=function()ls())
> B.but <- tkbutton(tt,text="B",command=function()ls())
> C.but <- tkbutton(tt,text="C",command=function()ls())
> D.but <- tkbutton(tt,text="D",command=function()ls())
>
> tkgrid(A.but,row=1,column=1,columnspan=2,rowspan=2,sticky="nswe")
> tkgrid(B.but,row=3,column=1,columnspan=2,rowspan=1,sticky="nswe")
> tkgrid(C.but,row=1,column=3,columnspan=2,rowspan=1,sticky="wens")
> tkgrid(D.but,row=3,column=3,columnspan=2,rowspan=2,sticky="wens")
>
> any idea?
>
The row for D.but should be 2, not 3 though I would index at 0 not 1:
tkgrid(A.but,row=1-1,column=1-1,columnspan=2,rowspan=2,sticky="nswe")
tkgrid(B.but,row=3-1,column=1-1,columnspan=2,rowspan=1,sticky="nswe")
tkgrid(C.but,row=1-1,column=3-1,columnspan=2,rowspan=1,sticky="wens")
tkgrid(D.but,row=3-1-1,column=3-1,columnspan=2,rowspan=2,sticky="wens")
Then to get the buttons to expand into the allocated sace, you can configure
the row and column weights:
sapply(0:3, function(i) {
if(i < 3) tkgrid.rowconfigure(tt, i, weight = 1)
tkgrid.columnconfigure(tt, i, weight = 1)
})
> thx
>
> Vincent
>
> [[alternative HTML version deleted]]
>
>
More information about the R-help
mailing list