Here is one approach: getInfo <- function() { require(tcltk) tt <- tktoplevel() trials <- tclVar(100) Stimuli <- tclVar(10)
f1 <- tkframe(tt) tkpack(f1, side='top') tkpack(tklabel(f1, text='trials: '), side='left') tkpack(tkentry(f1, textvariable=trials), side='left') f2 <- tkframe(tt) tkpack(f2, side='top') tkpack(tklabel(f2, text='Stimuli: '), side='left') tkpack(tkentry(f2, textvariable=Stimuli), side='left') tkpack(tkbutton(tt, text='Exit', command=function() tkdestroy(tt)), side='right', anchor='s') tkwait.window(tt) return( c(trials=as.numeric(tclvalue(trials)), Stimuli=as.numeric(tclvalue(Stimuli))) ) } out <- getInfo() out Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 > -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > project.org] On Behalf Of einsundeins > Sent: Monday, September 28, 2009 2:02 PM > To: r-help@r-project.org > Subject: [R] re trieve user input from an tcl/tk interface > > > Hello everyone, > > this is my first post here and I hope I signed up correctly and someone > will > take me by the hand and help me out. I am new to R and cannot figure > out > what to do here... > > ... I want to have an User Interface that requests input. I want to > save > this input to a variable to use it later on. I was able to do this with > a > modalDiaglog ( > http://bioinf.wehi.edu.au/~wettenhall/RTclTkExamples/modalDialog.html > like > this ) but I cannot figure out how to do this with multiple values to > be > read. > > I want to run a rather simple simulation and the user has to be able to > set > multiple parameters (say, number of trials and stimuli). The onOK- > function > should then "collect" these parameters and save them to variables (I > guess). > > Here is a snippet of my code. Could someone tell me what to do? Am I > heading > in the right direction or is my approach hopeless? :p > > ------------------------------------------------------------- > OnOK = function(){ > # I reckon this is where the important stuff should happen... > tkdestroy(tt) > } > > require(tcltk) > tclRequire("BWidget") > tt = tktoplevel() > > trials = tclVar("100") # I want to suggest default values but > they > should be editable. > entry.trials = tkentry(tt, width = "3", textvariable = trials) > tkgrid(tklabel(tt,text="Number of trials:")) > tkgrid(entry.trials) > > Stimuli = tclVar("10") # I want to suggest default values but > they > should be editable. > entry.Stimuli = tkentry(tt, width = "3", textvariable = Stimuli) > tkgrid(tklabel(tt, text = "Number of stimuli:")) > tkgrid(entry.Stimuli) > > OK.but = tkbutton(tt,text=" Go! ",command=OnOK) > tkgrid(OK.but) > tkfocus(tt) > ------------------------------------------------------------- > > Of course, I also tried to find a solution via google but couldn't > really > find anything. > http://tolstoy.newcastle.edu.au/R/e4/help/08/07/17422.html > The only thing I found was this post which never got answered . I hope > someone can help. Thank you very much for reading this and any help is > greatly appreciated! > > Best regards, > Florian > -- > View this message in context: http://www.nabble.com/retrieve-user- > input-from-an-tcl-tk-interface-tp25651905p25651905.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@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. ______________________________________________ R-help@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.