in reply to Tk:Text resize dillema

I'd like to do is to make the Text widget only as large as I need to given the number of lines that are in the widget at the time.

I don't think that should be too hard, since the text widget's height and width options are in terms of lines and character width. If you say -height=>4, -width=>25, that is 4 lines and 25 characters.

I havn't tried a $mw configure yet, but as esserte said, you may run into an infinite feedback loop if you try to reconfigure the $text widget as the $mw is being resized. You might be able to work out a flag, that gets set when the $mw resize starts, and is unset on the Button-1 Release. Then do your $text resize after the $mw resize is finished.

But back to the point of pixel size -vs -character size, look at this script, you don't need to worry about pixels. I didn't adjust for line width, but all you would need to do is loop through each line, take it's 'length' then reconfigure your $text widget -width option to the max length.

P.S. I guess there would be some trouble if you went to a very small window size, and you needed to search for a font that would fit and still be legible. All systems don't have the same fonts installed, so that is another problem.

#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = tkinit; $mw->fontCreate('big', -family=>'courier', -weight=>'bold', -size=>int(-18*18/14)); my $tx = $mw->Text( -height => 4, #initialy set it small -width => 25, )->pack(); foreach (1 .. 20 ) { $tx->insert( 'end', "line$_\n" ); } $tx->insert('end', "Blah " x 10); my $end = $tx->index('insert'); #get last line $tx->configure(-height=>$end); my $button = $mw->Button(-text=>'Reconfigure', -command=>sub{ $tx->configure(-font => 'big'); $tx->update; $tx->configure(-height => $end); }, )->pack(); MainLoop;

I'm not really a human, but I play one on earth. Cogito ergo sum a bum