[R] gWidgetstcltk gtext problem

j verzani jverzani at gmail.com
Sun Apr 1 19:33:12 CEST 2012


mrzung <mrzung46 <at> gmail.com> writes:

> 
> hi, what I want to do is put a function result(output) into gtext area.
> short example is following,
> 
> require("gWidgetstcltk")
> options(guiToolkit = "tcltk")
> 
> win<-gwindow()
> input<-gedit("",con=win)
> run<-gbutton("run",con=win,handler=function(h,...){
> y<<-as.numeric(svalue(input))+1
> })
> outarea<-gtext("",con=win)
> 
> in this case, I want to put "y" value into "outarea" whenever click the
> "run" button.
> specifically, I want to solve this problem by gWidgetstcltk.
> 
> Thanks
> 


The following shows how you can do this. The main answer is 
use svalue<- to set the contents of the gtext area, or use 
insert() to append text. 

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

w <- gwindow("output", visible=FALSE)
g <- ggroup(cont=w, horizontal=FALSE)

g1 <- ggroup(cont=g)
input <- gedit("", cont=g1, expand=TRUE)
btn <- gbutton("run", cont=g1)
output <- gtext("", cont=g)

visible(w) <- TRUE

run <- function(h,...) {
  val <- svalue(input)
  svalue(output) <- as.numeric(val) + 1
}

sapply(list(btn, input), addHandlerChanged, handler=run )



More information about the R-help mailing list