[R] tcltk again

Peter Dalgaard p.dalgaard at biostat.ku.dk
Sat Dec 29 21:31:34 CET 2007

Richard Müller wrote:
> Hello,
> the admonition of Prof. Ripley to search the documentation to solve my problem 
> helped, today I read a lot more on Tcl/Tk than before ;-)
> But now I'm stuck again. With the help of my script some functions are plotted 
> on the display, then I ask if the user wants to save it as pdf. In windows I 
> use winDialog and it works. But I can't succeed in Linux. In short:
> ----------------------------------------------------
> X11()
> ...
> res <-    tkmessageBox(title="Beenden?", 
>       message="Vor dem Beenden als PDF speichern?", 
>       icon="question", type="okcancel")
> if (tclvalue(res) == "ok")
> ...
> -----------------------------------------------------
> So far every thing is OK. Now I want a box the user should fill in the choosen 
> filename (with a default)
> and then
> --------------------
> pdf(filename)
> ...
> --------------------
> I experimented with tkgetSaveFile(). But in the moment the user gives the 
> filename the file is not yet generated! And I can't generate it in advance, 
> because the filename is not yet specified.
I don't see what the problem is here.

fn <- tkgetSaveFile() allows you to select an existing file OR navigate to a directory and type in the name of a new file. In either case, you can feed tclvalue(fn) to pdf(). 

If you cancel the operation, then tclvalue(fn)=="", so test for that first.

> So I looked for a dialog box. [Some boxes are called "dialog boxes" though 
> they only talk _to_ the user (besides the user's "yes" or "no")]. Just a 
> simple box with a text field the user can type in and the value of this field 
> given back.
> One option was the "modal dialog", but I was not able to pick the essentials 
> out of it. I did not want to press several buttons until the necessary window 
> appears. Also the "editable text window" was not really a solution.
> Perhaps a small hint again?
> Richard

   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907

More information about the R-help mailing list