-----Original Message-----
From: Prof Brian Ripley [mailto:ripley@stats.ox.ac.uk]
Sent: Monday, February 28, 2005 9:25 AM
To: John Fox
Cc: r-devel@stat.math.ethz.ch
Subject: Re: [Rd] Getting width of Tk text widget via tcltk
On Mon, 28 Feb 2005, John Fox wrote:
Dear list members,
Is it possible via a suitable tcltk command to get the *current*
width, in characters, of a Tk text widget that has been
the mouse? In the following code, the reported width of the text
widget doesn't change, even though it has been resized. I
can, however, get the current width in pixels:
library(tcltk)
top <- tktoplevel()
textWindow <- tktext(top, bg="white", height=20, width=80,
wrap="none") tkgrid(textWindow, sticky="news")
tkgrid.rowconfigure(top, 0, weight=1)
tkgrid.columnconfigure(top, 0, weight=1)
tkcget(textWindow, width=NULL)
tkwinfo("width", textWindow$ID)
# resize window with mouse
tkcget(textWindow, width=NULL)
tkwinfo("width", textWindow$ID)
<Tcl> 743
I could convert pixels to characters, but wonder whether I
I suspect you may have some difficulty with the latter, even
in a monospace font. Notice that 486 is not a multiple of
80, and if that is actually 81, 743 is not a multiple of 6.
I was trying to do this with heights for a listbox a few days
ago, and it seems that the line spacing is actually 1 pixel
greater than is reported.
Since you can resize to a non-integer number of lines I don't
believe (and I tried to read the source code) that Tcl/Tk
works internally with characters.
--
Brian D. Ripley, ripley@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 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595