Re: [Rd] Getting width of Tk text widget via tcltk

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Tue 01 Mar 2005 - 06:57:33 EST

"John Fox" <jfox@mcmaster.ca> writes:

> Dear Peter,
>
> As you can see from the expression, I didn't use integer division, nor did I
> round() or floor(). Here's my original example, using a monospaced font:
>
> > library(tcltk)
> > top <- tktoplevel()
> > textWindow <- tktext(top, bg="white", height=20, width=80, wrap="none",
> + font=tkfont.create(family="courier", size=10))
> > tkgrid(textWindow, sticky="news")
> <Tcl>
> > tkgrid.rowconfigure(top, 0, weight=1)
> <Tcl>
> > tkgrid.columnconfigure(top, 0, weight=1)
> <Tcl>
> > tkcget(textWindow, width=NULL)
> <Tcl> 80
> > tkwinfo("width", textWindow$ID)
> <Tcl> 646
> >
> > (as.numeric(tkwinfo("width", textWindow$ID))
> + - 2*as.numeric(tkcget(textWindow, borderwidth=NULL)) - 4) /
> + as.numeric(tkfont.measure(tkcget(textWindow, font=NULL), "0"))
> [1] 79.75
> >
> > (as.numeric(tkwinfo("width", textWindow$ID))
> + - 2*as.numeric(tkcget(textWindow, borderwidth=NULL)) - 2) /
> + as.numeric(tkfont.measure(tkcget(textWindow, font=NULL), "0"))
> [1] 80
>
> I believe that the right answer is 80, and this appears correct visually,
> confirmed by typing in the window.

Interesting...

> tkwinfo("width", textWindow)

<Tcl> 488
> (as.numeric(tkwinfo("width", textWindow))
+ - 2*as.numeric(tkcget(textWindow, borderwidth=NULL)) - 4) / + as.numeric(tkfont.measure(tkcget(textWindow, font=NULL), "0")) [1] 80
> (as.numeric(tkwinfo("width", textWindow))

+       - 2*as.numeric(tkcget(textWindow, borderwidth=NULL)) - 2) /
+       as.numeric(tkfont.measure(tkcget(textWindow, font=NULL), "0"))
[1] 80.33333

Notice, btw, that textWindow$ID shouldnn't be necessary.

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907

______________________________________________
R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Tue Mar 01 07:04:53 2005

This archive was generated by hypermail 2.1.8 : Tue 01 Mar 2005 - 07:42:11 EST