Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Width mismatch between text widget and font measure

31 views
Skip to first unread message

Torsten

unread,
Oct 11, 2015, 1:35:53 PM10/11/15
to
Hi,

The text widget docu says that '"0" is used in translating from character units to screen units.'. There is a mismatch with the results from "font measure".

package require Tk
set w0 [font measure TkMenuFont "0"]
set w1 [font measure TkMenuFont [string repeat "0" 60]]
text .t1 -height 20 -width 60 -font TkMenuFont
pack .t1
update
set w2 [winfo width .t1]
puts "w0= $w0, w1= $w1, w2= $w2"

Windows:
w0= 6, w1= 360, w2= 364
6*60= 360 OK, but 364?
Mac OS:
w0= 9, w1= 532, w2= 548
9*60= 540 is neither 532 nor 548. The difference of 16px is almost the width of two characters!

I have observed the differences on all (!) versions of operating systems over the last years. It is also independent from the font.
This is annoying when you try to predict the width of a text window prior to mapping it.

Who can explain the difference?

Torsten

Francois Vogel

unread,
Oct 11, 2015, 1:59:11 PM10/11/15
to
Torsten a écrit le 11/10/2015 19:35 :
> The text widget docu says that '"0" is used in translating from character units to screen units.'. There is a mismatch with the results from "font measure".
>
> package require Tk
> set w0 [font measure TkMenuFont "0"]
> set w1 [font measure TkMenuFont [string repeat "0" 60]]
> text .t1 -height 20 -width 60 -font TkMenuFont
> pack .t1
> update
> set w2 [winfo width .t1]
> puts "w0= $w0, w1= $w1, w2= $w2"
>
> Windows:
> w0= 6, w1= 360, w2= 364
> 6*60= 360 OK, but 364?

You get what you expect (w2 = 360) if you configure the text widget
with -padx 0 -borderwidth 0.
These two options have default value 1 and that is counted (twice for
each) in the total width returned by winfo width .t1

> Mac OS:
> w0= 9, w1= 532, w2= 548
> 9*60= 540 is neither 532 nor 548. The difference of 16px is almost the width of two characters!
Cannot check/investigate 'cause no Mac OS reachable for me, sorry.

Regards,
Francois

0 new messages