[R] tklistbox - R-Objekt

Greg Snow Greg.Snow at imail.org
Mon Nov 24 20:19:27 CET 2008


This is safest if the below code is wrapped in another function.

At the top level function (or whatever level you will be using your choice information at) first create the variable named choice with a default value (choice <- "").

In your OnOk function, change "choice<-" to "choice<<-", this will make the function change the value of the previously created variable, rather than create a local variable (which goes away before you do anything with it).

Hope this helps,

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of thoeb
> Sent: Sunday, November 23, 2008 12:18 PM
> To: r-help at r-project.org
> Subject: [R] tklistbox - R-Objekt
>
>
> Hello, I have a problem with a tklistbox. The user should be able to
> choose
> one out of two calculation methods needed for further calculations. My
> r-script for that purpose looks like that:
>
>     require(tcltk)
>     tt<-tktoplevel()
>     tl<-tklistbox(tt,height=4,selectmode="single",background="white")
>     tkgrid(tklabel(tt,text="select method for LAI calculation"))
>     tkgrid(tl)
>     method<- c("method1","method2")
>     for (i in (1:2)){
>         tkinsert(tl,"end",method[i])
>         }
>     tkselection.set(tl,0)
>     OnOK <- function(){
>         choice<-method[as.numeric(tkcurselection(tl))+1]
>            tkdestroy(tt)
>             }
>     OK.but <-tkbutton(tt,text="   OK   ",command=OnOK)
>     tkbind(tkgrid, "<Return>",OnOK)
>     tkgrid(OK.but)
>
> The function works, but it does not create any r-object to that I can
> access
> later on. How do I have to modify the function that I get an object
> with the
> value "method1" or "method2"?
>
> -----
> Tamara Hoebinger
> University of Vienna
> --
> View this message in context: http://www.nabble.com/tklistbox---R-
> Objekt-tp20649714p20649714.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list