[R-gui] tktable topleft

jverzani jverzani at gmail.com
Sun May 17 17:24:42 CEST 2009


David Katz <david <at> davidkatzconsulting.com> writes:

> 
> How can I access the row and column of  the tktable that is visible in the
> top left corner of the display?
> The docs mention an index called topleft but I don't know how to access it
> from the tcltk package.
> 

The topleft index refers to the top left editable cell. Try the 0,0 index, as in
the code below:

library(tcltk)
tclRequire("Tktable")
a <- tclArray()
m <- rbind(c("","h1","h2"),
           c("r1", "1", "2"),
           c("r2", "3", "4"))
## col. headings
sapply(2:ncol(m), function(j) 
       a[[0,j-1]] <- as.tclObj(m[1,j]))
## fill in row by row
sapply(2:nrow(m), function(i)
       sapply(1:ncol(m), function(j)
              a[[i-1, j-1]] <- as.tclObj(m[i,j])))

w <- tktoplevel()
tbl <- tkwidget(w, "table", variable=a,
                rows = nrow(m),
                cols = ncol(m),
                titlerows=1, titlecols=1)
tkpack(tbl)


## adjust upper cell
tkset(tbl,"0,0","text")

--John



More information about the R-SIG-GUI mailing list