#!/usr/bin/perl
use strict;
use Tk;
use Tk::Label;
our $mw = Tk::MainWindow->new();
my $lab1=$mw->Label(-text => 'abc abc abc abc abc abc abc abc abc abc abc abc',
-wraplength => 20)->pack;
$lab1->bind('<Configure>',\&rewrap);
my $lab2=$mw->Label(-text => 'abc abc abc abc abc abc abc abc abc abc abc abc',
-wraplength => 20)->pack;
$lab2->bind('<Configure>',\&rewrap);
MainLoop;
sub rewrap
{
$mw->Widget($_[0]->{_TkValue_})->configure(-wraplength => ($mw->width > 20 ?
$mw->width : 21) - 20);
}
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail.
Send me your mail from another non-spammer site please.)
Please reply to <petr AT practisoft DOT cz>
>I have placed few Labels into main window but need to change -wraplength option
>for all Labels every time the mainwindow is resized. The program bellow do what
>I need but have anybody a better idea to avoid too many binds?
>
>#!/usr/bin/perl
>use strict;
>use Tk;
>use Tk::Label;
>
>our $mw = Tk::MainWindow->new();
>my $lab1=$mw->Label(-text => 'abc abc abc abc abc abc abc abc abc abc abc abc',
> -wraplength => 20)->pack;
>$lab1->bind('<Configure>',\&rewrap);
>
>my $lab2=$mw->Label(-text => 'abc abc abc abc abc abc abc abc abc abc abc abc',
> -wraplength => 20)->pack;
>$lab2->bind('<Configure>',\&rewrap);
>
>MainLoop;
>
>sub rewrap
>{
>$mw->Widget($_[0]->{_TkValue_})->configure(-wraplength => ($mw->width > 20 ?
>$mw->width : 21) - 20);
>}
I don't really know what you are trying to do, but you may be getting
confused because the -wraplength option seems to be in pixels, where
-width is in chars.
See if this gives you ideas:
#!/usr/bin/perl
use strict;
use Tk;
use Tk::Label;
our $mw = Tk::MainWindow->new();
my $lab1=$mw->Label(-text => 'abc abc abc abc abc abc abc abc abc abc
abc abc',
-bg=>'white',
-width => 40,
-wraplength => 200,
)->pack(-expand=> 0, -fill=> 'x');
my $lab2=$mw->Label(-text => 'abc abc abc abc abc abc abc abc abc abc
abc abc',
-bg=>'lightblue',
-width => 40,
-wraplength => 200,
)->pack(-expand=> 0, -fill=> 'x');
MainLoop;
__END__
zentara
--
I'm not really a human, but I play one on earth.
http://zentara.net/Remember_How_Lucky_You_Are.html
<table width="100%">
<tr><td>bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla</td></tr>
<tr><td>bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla</td></tr>
<tr><td>bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla</td></tr>
<tr><td>bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla</td></tr>
</table>
>Hi zentara,
>I not see any idea except -expand and -fill parameters in pack() :-) But this
>not help me. I want to do some other.
>When I not set -width for Label then width of Label is set to needed length to
>view text but max to screen width (if mainwindow width is not set in other way).
>So label's text is displayed in single row. When I shring mainwindow width I
>want to set label -wraplength to mainwindow width - few pixels (border + small
>x-spaces). Please try again my previous example and try to shring mainwindow
>width ;-) You will se what I want to do. But, maybe, it can be done better.
>In other words: I need the same effect as html code bellow when browser width is
>resized to say 50 pixels :-)
>
><table width="100%">
><tr><td>bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla</td></tr>
><tr><td>bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla</td></tr>
><tr><td>bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla</td></tr>
><tr><td>bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla</td></tr>
></table>
I think you will need to go to a Tk::TableMatrix to get table resizing.
Here is something to look at, it's not perfect, but may show you a way.
#!/usr/bin/perl
use warnings;
use strict;
use Tk;
use Tk::TableMatrix;
my $mw = MainWindow->new;
my $arrayVar = {};
my ($rows,$cols) = (2, 2);
foreach my $row (0..($rows-1)){
foreach my $col (0..($cols-1)){
$arrayVar->{"$row,$col"} = 'abcdefghijklmnopqrstuvwxyz';
}
}
my $t = $mw->TableMatrix(
-rows => 2,
-cols => 2,
-width => 10,
-height => 10,
-titlerows => 0,
-titlecols => 0,
-variable => $arrayVar,
#-coltagcommand => \&colSub,
#-browsecommand => \&brscmd,
-colstretchmode => 'all',
-rowstretchmode => 'all',
-drawmode => 'slow',
-wrap => 10,
)->pack(-expand=>1,-fill=>'both');
Tk::MainLoop;