[R] use gcheckbox in gWidgets to switch on/off gframe

tonja.krueger at web.de tonja.krueger at web.de
Sat Jan 16 15:53:54 CET 2016



Dear All,
I’m trying to create a GUI using gWidgets.
I would like to have a checkbox to “switch on/off” different frames within the GUI. Ideally if one frame is switched on, all other frames would be switched off.
Unfortunatly I only came as far as this: 

library(gWidgets) 
Population <- c("A","B","C","D","E","F")
w = gwindow("")
g1 = ggroup(horizontal = F, cont=w)
g2 = ggroup(horizontal = T, cont=g1)
glabel("Population:", cont=g2)
Station = gcombobox(Population, editable=F, cont=g2, handler=NULL)
gseparator(horizontal=T, container=g1, expand=F)
gcheckbox("checked", container=g1, handler=function(h,...) {
enabled ( frame1 ) <-  cat(svalue(h$obj))
})
frame1 <- gframe ( "A:" , cont = g1 , horizontal=FALSE )
lyt1 <- glayout ( cont = frame1)
widget_list <- list ( )
lyt1 [1,1] <- "A1:"
lyt1 [1,2,expand = TRUE] <- (widget_list$A1 <- gedit(" ", cont=lyt1, handler=NULL))
lyt1 [2,1] <- "A2:"
lyt1 [2,2,expand = TRUE] <- (widget_list$A2 <- gedit(" ", cont=lyt1, handler=NULL))
gcheckbox("checked", container=g1, handler=function(h,...) {
enabled ( frame2 ) <-  cat(svalue(h$obj))
})
frame2 <- gframe ( "B:" , cont = g1 , horizontal=FALSE )
lyt2 <- glayout ( cont = frame2)
widget_list <- list ( )
lyt2 [1,1] <- "B1:"
lyt2 [1,2, expand = TRUE] <- (widget_list$B1 <- gedit(" ", cont=lyt2, handler=NULL))

When I type in: 
enabled ( frame2 ) <-  F; enabled ( frame2 ) <-  T
it does what I would like it to do. But when I check the checkbox it will only work once. Thank you for any suggestions!
Tonja



More information about the R-help mailing list