简体   繁体   中英

R tcltk, tkframe expansion

I am thinking of creating a widget with 2 checkbuttons, each in a tkframe. By clicking the 1st checkbutton, I hope the 1st frame will expand to display more lines of options. But when clicking the 2nd checkbutton, I hope the 2nd frame will expand but the 1st frame will reduce to include only the 1st checkbutton. It is like several hidden lines being activated by clicking the checkbutton. Does anyone know how to do this?

thanks, DD

You can get something like this within gWidgets for tcltk (or gWidgets2 on github, where you can see how it is done https://github.com/jverzani/gWidgets2tcltk/blob/master/R/gexpandgroup.R ). Here is the pattern:

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)

The expandgroup widget really only works when stacked, not side-by-side. Integrating this into a GUI with plain tcltk is not impossible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM