This sub takes a single line Tk text widget reference (such as a Label) and a string then sets the font size in the widget to maximise the size of the text without clipping.
Place this in the resize handler for a widget to resize the text when the widget size changes.
sub SetBigText { my ($widget, $text) = @_; my $font = $widget->Font (); my $widthF = $widget->fontMeasure ($font, $text); my $heightF = $widget->fontMetrics($font, -linespace); my $xRatio = $widget->width / $widthF; my $yRatio = $widget->height / $heightF; my $minRatio = $xRatio < $yRatio ? $xRatio : $yRatio; my $fontSize = $widget->fontActual ($font, -size); my $newSize = $minRatio * $fontSize; $font->configure (-size => $newSize); $widget->configure (-text => $text); $widget->configure (-font => $font); }
In reply to Tk: Set text size in a widget by GrandFather
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |