|
#!usr/bin/perl
# listbox.pluse warnings;
use strict;
use Tk;
my $status = 'Your favorite color is not yet entered';
my @colors =qw(Red Green Orange White Yellow Purple Blue Black);
my $mw = MainWindow->new;$mw->title('Listbox Example');
my $label = $mw->Label(-textvariable => \$status);
my $enter = $mw->Label(-text => 'Enter your favorite color(s)');
my $lb = $mw->Listbox(-selectmode => 'multiple');$lb->insert('end', sort @colors);
my $show = $mw->Button(-text => 'Show selections', -command => [\&display]);
my $exit = $mw->Button(-text => 'Exit', -command => [$mw => 'destroy']);
$label->pack;
$enter->pack;
$lb->pack;
$show->pack;
$exit->pack;
MainLoop;
sub display {
my @selections = $lb->curselection;
$status = "You selected: \n";
foreach (@selections) {
$status .= $lb->get($_) . "\n";
}
$lb->selectionClear(0, 'end');
}
|
|