On 12 Dec 2014, at 11:02 , Jouanin Celine <celine_joua...@yahoo.fr> wrote:
> Hi dear R list, > I would like to create a graphical user interface with tcltk.I want to have a > window where the user will enter a numeric, this will open a message box with > his value. This works, but I don't succeed to get the value x, to use it > after in a script in the R console. The x variable doesn't give me the value > chosen by the user but returns the initial value "12".How can I do it ? Does > exist an another function in tcltk that I need to use ?Thanks for your help > Céline > Here is my code : > library(tcltk2) > tt<-tktoplevel() > tktitle(tt)<-"Select a value" > titre<-tklabel(tt, text="Select a value") > value<-tkentry(tt, width=3, textvariable=tclVar("12")) I'd prefer this pattern of coding: var <- tclVar("12") entry <- tkentry(.... textvariable=var) .... tkpack(entry) .... tclvalue(var) However, tkget() of an entry widget does return its value, so the direct cause of your trouble is different: > ok<-function() > { > show<-paste("The value is :", tclvalue(tkget(value))) > tkmessageBox(title="End", message=show, icon="info", type="ok") > tkdestroy(tt) > } > > bouton<-tkbutton(tt, text="OK", command=ok) > tkpack(titre) > tkpack(value,bouton) > x<-tclvalue(tkget(value)) > x<-as.numeric(x) > x #this give 12 but I want to have the new value > I think this fetches the value before you get a chance to change it. You need to wait for it, either using tkwait.variable or tkwait.window. I believe that the tkttest demo has this structure. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd....@cbs.dk Priv: pda...@gmail.com ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.