Tkinter measurements

John Velman velman at cox.net
Tue Sep 28 18:29:38 CEST 2004


On Tue, 28 Sep 2004 10:26:01 +0200, Eric Brunel wrote:

> John Velman wrote:
>> I want to draw a box around a short piece of text in canvas (one line
>> text).  I know how to do it if I place the text on the canvas first,then
>> draw the box around it. 
>> 
>> Is there a way to find out the dimensions of the text bounding box before
>> drawing it?

> 
> First: why do you want to do that? The most used method is to draw the
> text before, get its bounding box, then draw the box. Why do you want to
> do the opposite?
> 

That's a good question, all right.  I'm restarting in Python something I'd
originally started in perl with Perl/TK.  In my perl original my code was
pretty unstructured, and in redoing I decided to modularize (which Python
makes a lot easier!).  Without going into my whole possibly misbegotten
concept, my original idea for modules seemed to require knowing the text
size.  Probably a better design will let me do the text, then the box as
you suggest.   Sometimes I get hung up on a certain problem (in this case,
getting the text size before drawing it) and can't seem to move on until I
have a solution.  

Thanks for the good information about TkFont module, and the point sized
pseudo pixels!

And for the question "why?"  

Best,

John Velman

[snip]



More information about the Python-list mailing list