TK Label Constant Height w/ Different Font Sizes? 
Author Message
 TK Label Constant Height w/ Different Font Sizes?

I write a message into my status label with a smaller font (11 pt instead of
14 pt) when the message length exceeds the large-font width of the label. I
keep the label width constant by changing its font-relative width (from 26
chars to 33 chars, or 14/11*26). But I don't know how to keep the *height*
of the label from shrinking with the smaller font.

Any ideas?

-Ed Suominen



Mon, 12 Jul 2004 08:05:21 GMT  
 TK Label Constant Height w/ Different Font Sizes?

Quote:
> I write a message into my status label with a smaller font (11 pt instead
of
> 14 pt) when the message length exceeds the large-font width of the label.
I
> keep the label width constant by changing its font-relative width (from 26
> chars to 33 chars, or 14/11*26). But I don't know how to keep the *height*
> of the label from shrinking with the smaller font.

> Any ideas?

Put it in a frame, and force the frame to a specific height is one way of
doing it. Read up on "pack propagate", or "grid propagate" to see how you
can keep children from causing their parent to resize.


Mon, 12 Jul 2004 10:22:48 GMT  
 TK Label Constant Height w/ Different Font Sizes?

Quote:

> I write a message into my status label with a smaller font (11 pt instead of
> 14 pt) when the message length exceeds the large-font width of the label. I
> keep the label width constant by changing its font-relative width (from 26
> chars to 33 chars, or 14/11*26). But I don't know how to keep the *height*
> of the label from shrinking with the smaller font.

This is a feature of the BLT table geometry manager.  You can override the
widget's requested width and height with one of your own (in pixels).  It's
especially useful for widgets that don't let you specify their dimensions
in pixels (like the label).

        label .label1 -text "Label 1" -font { Helvetica 10 }
        label .label2 -text "Label 2" -font { Courier 14 }
        label .label3 -text "Label 3" -font { Times 18 }
        blt::table . \
            0,0 .label1 -width 1.5i -height 0.5i \
            0,1 .label2 -width 1.5i -height 0.5i \
            0,2 .label3 -width 1.5i -height 0.5i

You can even specify bounds for the dimensions (don't get wider than 2  
inches or thinner than 1 inch).

        blt::table configure . .label1 -width { 1.0i 2.0i 1.5i }

The three values are the minimum, maximum, and nominal widths.

--gah



Tue, 13 Jul 2004 04:12:05 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Font size varies in different Windows versions.

2. Variable name with different font size

3. tcl/TK or expect tk and font-size

4. Q: fixed window size for different fonts?

5. Font sizes across different platforms

6. Different word-wrap in Tk label vs text

7. Tk on Windows uses different font than native Windows applications

8. Constant size exceeds variable size?

9. Different window sizes in different sceen resolutions

10. setting font size in tk window

11. default font size in tk

12. Windows Tcl/Tk: Why diffent font size from version to version

 

 
Powered by phpBB® Forum Software