The HList widget is used to display data that has a hierarchial structure, such as a computer directory tree or a company's organization chart. The basic syntax for creating such a widget is The basic syntax is
my $hlist = $mw->HList( [ option => value ] );
Some common options are In addition, for creating and deleting items the following methods are available. Here is an example of its use:
# file hlist.pl
use Tk;
use strict;
use warnings;
use Tk::HList;
my $message = 'nothing yet ...';
my $mw = MainWindow->new;
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');
sub browse {
  my $choice = shift;
  $message = "You chose '$choice'";
which is illustrated in the screenshot below.

Figure 3.18: Example of a HList widget
Image hlist

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