my $label = $mw->Label( [ option => value ] );Two basic options are
#!perl
# file label.pl
use Tk;
use strict;
use warnings;
my $mw = MainWindow->new;
$mw->title('Label');
my $hello = $mw->Label(-text => 'Greetings!');
my $exit = $mw->Button(-text => 'Exit',
-command => [$mw => 'destroy']);
$hello->pack(-side=>'top');
$exit->pack(-side => 'bottom');
MainLoop;
is an example of a fixed label, using the -text
option. This is illustrated in the figure below.
The second example,
#!perl
# file label1.pl
use Tk;
use strict;
use warnings;
my $greeting = 'Hello';
my $mw = MainWindow->new;
$mw->title('Label');
my $label = $mw->Label(-textvariable => \$greeting);
my $hello = $mw->Button(-text => 'Hello',
-command => \&hello);
my $goodbye = $mw->Button(-text => 'Goodbye',
-command => \&goodbye);
my $exit = $mw->Button(-text => 'Exit',
-command => [$mw => 'destroy']);
$label->pack(-side=>'top');
$exit->pack(-side => 'bottom', -fill => 'both');
$hello->pack(-side=>'left');
$goodbye->pack(-side=>'right');
MainLoop;
sub hello {
$greeting = 'Hello';
}
sub goodbye {
$greeting = 'Goodbye';
}
is an example of using the -textvariable option to
display a variable message.
This appears in the figure below.
The two buttons, $hello and $goodbye, simply change the value of $greeting, and when clicked subsequently change the label displayed.
Randy Kobes 2003-11-17