my $hlist = $mw->HList( [ option => value ] );Some common options are
#!perl
# file hlist.pl
use Tk;
use strict;
use warnings;
use Tk::HList;
my $message = 'nothing yet ...';
my $mw = MainWindow->new;
$mw->title('Dialog');
my $label = $mw->Label(-textvariable => \$message);
my $exit = $mw->Button(-text => 'Exit',
-command => [$mw => 'destroy']);
my $hlist = $mw->Scrolled('HList',
-itemtype => 'text',
-separator => '/',
-selectmode => 'single',
-browsecmd => \&browse,
);
my @dirs = qw(/ /home /home/joe /home/jane /usr
/usr/lib /usr/bin /usr/man /usr/include /usr/local
/usr/local/lib /usr/local/bin /usr/local/include
);
$hlist->add($_, -text => $_) for @dirs;
$exit->pack(-side => 'bottom');
$label->pack(-side => 'top');
$hlist->pack;
MainLoop;
sub browse {
my $choice = shift;
$message = "You chose '$choice'";
}
which is illustrated in the screenshot below.
Here the HList widget is created and populated, through the add method, with an array of directory names. When the user selects one of the entries, the browse callback is invoked, which changes the message associated with the $label widget to one refelcting which entry has been chosen.
Randy Kobes 2003-11-17