In addition to the idea of aligning your text to the upper left corner, you could put a newline(s) in your text, so that the "Send command XXXX\nto system YYYY" will clip the top line last. Also, you can declare your button text string before you build( or configure) the button, take the length of the text, and use the -width=>$length option. Think creatively. :-) You could also reconfigure your button text, whenever an resize takes place.
#!/usr/bin/perl
use Tk;
my $mw = new MainWindow;
my $currentSize = $mw->reqwidth . "x" . $mw->reqheight;
$mw->bind( '<Configure>', [ \&OnResize, \$currentSize ] );
MainLoop;
sub OnResize {
my ( $mw, $oldSize ) = @_;
my $newSize = $mw->width . "x" . $mw->height;
if ( $$oldSize ne $newSize ) {
## Resize has occurred do something:
printf( "Resize happened - old size: %s, new size: %s\n",
$$oldSize, $newSize );
## set the old size to the new size
$$oldSize = $newSize;
}
}
I'm not really a human, but I play one on earth.
flash japh
| [reply] [d/l] |
| [reply] |
I think there is a way to check how wide a text is using a particular font - but I don't have my Tk books here so I can't check. I might be totally wrong.
There might however be a simpler solution that does what you want. Try aligning your text in the button. By default, Tk will center text (and hence, if the widget is too small, only display the center part). If you tell Tk to put the text on the left, it will show the left part of the text if it gets clipped. Unfortunally, this has the drawback that if the text is smaller than the button, it won't be centered. If that's not what you want, disregard this suggestion. | [reply] |
Look at the base Widget code in man TK::Widget.
$widget->geometry gives widthxheight+x+y in pixels. Even a brute-force examination of this should allow you to re-size the font or re-configure the text string for the size of the button as displayed. While it would be nice to use the exact pixel-used count, most apps don't need that fine a control and can't waste the time. | [reply] |
| [reply] |