Two tcltk questions and Re: [R] tcltk package functionality

Peter Dalgaard BSA p.dalgaard at
Fri Sep 29 18:42:15 CEST 2000

Peter Wolf <pwolf at> writes:

> Here are another two tcltk question:
> 1. I want to add a scrollbar along the right side of a text widget. This can be
>    achieved by .Tk.ID(). Is there a way to avoid to call .Tk.ID ---
>    perhaps by using tkyview?
>    tk.test1 <- function(nmax=3){
>      library("tcltk")
>      tl         <- tktoplevel()
>      tl.text    <- tktext(tl)
>      tl.yscroll <- tkscrollbar(tl)
>      tkconfigure(tl.text,   yscrollcommand=paste(.Tk.ID(tl.yscroll),"set"  ))
>      tkconfigure(tl.yscroll,       command=paste(.Tk.ID(tl.text),   "yview"))
>      tkpack(tl.text, tl.yscroll, side="left", fill="y")
>      tkpack(tkbutton(tl, text="exit", command=function()tclvar$done<-"T"))
>      tclvar$done <- "F"; tkwait.variable("done")
>      tkdestroy(tl)
>    }

One problem with this stuff is that the users seem to be quickly
becoming more proficient than the programmer... 

The first one is avoidable by a construction like

I.e. you get a callback to R instead. The yscrollcommand option works
by sticking arguments at the end of what the .Tcl.callback generates
for the function, so the callback is actually called with arguments
(%...,x,y) and you need to extract (x,y) by the above kludge (or
something equally kludgy). Ick.

Similarly, one can do 

*but* there's a varying number of arguments in this case, so it only
works on the slider of the scrollbar, not the arrowheads at the end.
You need to apply an alternate kludge to pass all arguments except the
first on to tkyview (exercise for the reader...)

Alternatively tell me how to avoid producing that "%..." argument on
callbacks and command=function(...)tkyview(tl.yscroll,...) should
work. I suspect that it might be easy.

> 2. If I try to insert a text containing an unequal number of "{" and "}"
>    brackets tkinsert stops with the error message:
>      Error in .Tcl(.Tcl.args(...)) : [tcl] extra characters after close-brace.
>    How can I change this behavior?
>    tk.test2 <- function(nmax=3){
>      library("tcltk")
>      tl         <- tktoplevel()
>      tl.text    <- tktext(tl)
>      tkpack(tl.text)
>      for(i in 1:nmax){
>        cat("input text? "); input.text<-readline()
>        tkinsert(tl.text,"0.0",input.text)
>      }
>      tkdestroy(tl)
>    }

By fixing the bug ;) This has been waiting to happen. The quoting
mechanisms of Tcl makes it impossible to get an unbalanced set of
braces into a {...}-delimited string and this is what the .Tcl
interface is producing. So one really needs to use "..." delimiting
with the entire morass of special character escapes. This is due to
sheer laziness on my part (or slightly nicer put: my mind was
focused elsewhere at the time).

   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at             FAX: (+45) 35327907
r-help mailing list -- Read
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at

More information about the R-help mailing list