[R] Tcl/Tk doubt

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Mon Jul 15 11:33:34 CEST 2002


Bernardo Rangel Tura <tura at centroin.com.br> writes:

> Good Night R experts
> 
> I make a Tcl/Tk script for generate a histogram from normal distribuition.
> 
> ----------------------------
> gnorm<-function(){
>         require(tcltk) || stop("tcltk support is absent")
>         base <- tktoplevel()
>         done <- tclVar(0)
>         mu=tclVar(2)
>         var=tclVar(2)
>         tkwm.title(base,"Gráfico da Normal")
>         heading <- tklabel(base, text="Parâmetros")
>         l.mu <- tklabel(base, text="Média")
>         l.var <- tklabel(base, text="Variância")
>         mu.entry <- tkentry(base, textvariable=mu)
>         var.entry <- tkentry(base, textvariable=var)    
>         tkgrid(heading, columnspan=2)
>         tkgrid(l.mu, mu.entry)
>         tkgrid(l.var, var.entry)
>         mu<-tclvalue(mu.entry)
>         but<-tkbutton(base, text="ok",command=function() {
>                 tclvalue(done)<-1
>                 })
>         tkgrid(but)
>         tkwait.variable(done)
>         mu<- as.numeric(tclvalue(mu))
>         var<- as.numeric(tclvalue(var.entry))
>         x<-rnorm(100,mean=mu,sd=sqrt(var))
>         hist(x)
>         }
> gnorm()
> ----------------------------
> When I click button OK show this error mensage:
> Error in structure(.External("dotTcl", ..., PACKAGE = "tcltk"), class = "tclObj") : 
>         [tcl] can't read "<environment>": no such variable.
> 
> Where this my mistake? Which the correct code?

You have 

mu<-tclvalue(mu.entry)

and then after activating the button

mu<- as.numeric(tclvalue(mu))

I don't think the first one of these makes sense, and certainly, after you
redefined mu, the second one is not going to work.

You also want "var", not "var.entry" in 

 var<- as.numeric(tclvalue(var.entry))

With those changes things seem to work, except that you need to
destroy the widget after use.

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list