R tcltk,tkframe扩展

时间:2013-03-28 07:27:36

标签: r tk

我正在考虑使用2个检查按钮创建一个小部件,每个按钮位于一个tkframe中。通过单击第一个复选按钮,我希望第一帧将展开以显示更多行选项。但是当点击第二个按钮时,我希望第二帧会扩展,但第一帧将减少,只包括第一个按钮。这就像通过单击checkbutton激活几条隐藏线。有谁知道怎么做?

感谢, DD

1 个答案:

答案 0 :(得分:2)

你可以在gWidgets中为tcltk(或github上的gWidgets2,你可以看到它是如何完成的https://github.com/jverzani/gWidgets2tcltk/blob/master/R/gexpandgroup.R)得到类似的东西。这是模式:

library(gWidgets)
options(guiToolkit="tcltk")

lorem <- "lorem ipsum dolor sit amet, consectetur adipiscing
elit. Suspendisse tempus aliquam ante, at malesuada tellus
vulputate at. Morbi ac diam augue, vel bibendum lorem.
Curabitur ut est molestie leo sagittis vestibulum.
"

w <- gwindow()
size(w) <- c(800, 400)
g <- ggroup(cont=w, horizontal=FALSE)
expand1 <- gexpandgroup("frame 1", cont=g, anchor=c(-1,1))
expand2 <- gexpandgroup("frame 2", cont=g, anchor=c(-1,1))
visible(expand2) <- FALSE

## put stuff into expanding groups
glabel(lorem, cont=expand1)
glabel(lorem, cont=expand2)

callback <- function(h,...) {
  print("click 2")
  if(visible(expand2) & visible(expand1))
    visible(expand1) <- FALSE
}
addHandlerChanged(expand2, callback)

expandgroup小部件实际上只在堆叠时才有效,而不是并排。使用普通的tcltk将其集成到GUI中并非不可能。