[R] gWidgets (tcltk): problem extracting values from widgets in glayout grid
englund.evan at epamail.epa.gov
englund.evan at epamail.epa.gov
Thu Aug 23 19:41:50 CEST 2007
Thanks, John. That works... The following is a trivial but complete
application that uses glayout to
position the widgets, then lets you edit a parameter and execute a
function that uses the parameter:
##################################
### glayout example
wtesta = gwindow("Sample Histogram",visible=TRUE)
wtestb = glayout(visible=TRUE,container=wtesta)
wtestb[1,1] = glabel("Population Mean",container=wtestb)
### the gedit widget is assigned to "gWpopmean" for future reference
wtestb[2,1] = (gWpopmean = gedit("10",container=wtestb,width=5))
wtestb[2,2] = gbutton("Plot
Histogram",container=wtestb,handler=function(h,...){myplot()})
myplot = function()
{
popmean = as.numeric(svalue(gWpopmean))
hist(rnorm(100,popmean,1))
}
####################################
Dear Evan,
<englund.evan <at> epamail.epa.gov> writes:
>
>
> Hello,
>
> I haven't been able to find an example for the second case below -- or
> perhaps I didn't recognize it when I saw it.
> Is there a value for x such that svalue(x) will return "bbb", either
by
> itself or as part of an array? Or do I need to do something else
> entirely?
> (R2.5.1; Windows XP)
>
You will need to store the widget. See below.
> > ### Case 2: this makes an identical window & widget, with "b"
> replacing "a"
> > ### but does't return the value
> > wtesta = gwindow("wtestb",visible=TRUE)
> > wtestb = glayout(visible=TRUE,container=wtesta)
> > wtestb[1,1]=gedit("bbb",container=wtestb)
> > print(svalue(wtestb[1,1]))
the glayout container doesn't work that way. You don't get a [
method, just a [<- one. Try something like this instead to store the
widget:
wtestb[1,1]=(bbb <- gedit("bbb",container=wtestb) )
print(svalue(bbb))
--John
Evan Englund
U.S. EPA
702-798-2248
More information about the R-help
mailing list