I want to set up a simple Tk dialog interface to a function in R, such that when the "OK" button is pressed, the dialog window is destroyed and then R does its work on the data/parameters/whatever that were entered in the dialog. The function "test" below is a simple prototype. My problem: upon running test() and hitting "OK", R does its work (ie, computes rnorm(400000) in the silly example below), and only *after* that does the dialog window disappear. Is there some way to make sure that the window disappears immediately after hitting "OK"? I am using R and Tcl/Tk under Darwin/X11. Exact version information below. I have made similar dialogs before with a Windows version and my recollection is that I didn't have this problem -- is it perhaps a system-dependent thing? Any hints would be welcomed. Thanks, David test<-function(){ require(tcltk) base<-tktoplevel() done<-tclVar(0) ok.but<-tkbutton(base,text="OK", command=function(){ tclvalue(done)<-3 }) tkpack(ok.but) tkwait.variable(as.character(done)) tkdestroy(base) x<-rnorm(400000) print("finished")}> version_ platform powerpc-apple-darwin5.3 arch powerpc os darwin5.3 system powerpc, darwin5.3 status major 1 minor 4.1 year 2002 month 01 day 30 language R -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Fri, 22 Feb 2002, David Firth wrote:> I want to set up a simple Tk dialog interface to a function in R, > such that when the "OK" button is pressed, the dialog window is > destroyed and then R does its work on the data/parameters/whatever > that were entered in the dialog. The function "test" below is a > simple prototype. > > My problem: upon running test() and hitting "OK", R does its work > (ie, computes rnorm(400000) in the silly example below), and only > *after* that does the dialog window disappear. Is there some way to > make sure that the window disappears immediately after hitting "OK"? > > I am using R and Tcl/Tk under Darwin/X11. Exact version information > below. I have made similar dialogs before with a Windows version and > my recollection is that I didn't have this problem -- is it perhaps a > system-dependent thing?Right: it disappears immediately on Windows. As far as I can tell on my fast Linux box (even across the net to my cable modem), there it has the effect you mention. BTW, to all those who have been saying that 1.4.1 is not easily available on MacOS X/darwin, note the details below.> platform powerpc-apple-darwin5.3 > arch powerpc > os darwin5.3 > system powerpc, darwin5.3 > status > major 1 > minor 4.1 > year 2002 > month 01 > day 30 > language R-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
David Firth <david.firth at nuffield.oxford.ac.uk> writes:> I want to set up a simple Tk dialog interface to a function in R, such > that when the "OK" button is pressed, the dialog window is destroyed > and then R does its work on the data/parameters/whatever that were > entered in the dialog. The function "test" below is a simple > prototype. > > My problem: upon running test() and hitting "OK", R does its work (ie, > computes rnorm(400000) in the silly example below), and only *after* > that does the dialog window disappear. Is there some way to make sure > that the window disappears immediately after hitting "OK"? > > I am using R and Tcl/Tk under Darwin/X11. Exact version information > below. I have made similar dialogs before with a Windows version and > my recollection is that I didn't have this problem -- is it perhaps a > system-dependent thing? > > Any hints would be welcomed.Hmm... I wonder if we're not missing a way to force a run of the Tcl event loop, but the canonical way would be (I think) to make the button callback destroy the window and use tkwait.window(base) rather than tkwait.variable(). -- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._