The HList Family of Widgets
The HList widget is the basis for the two other Tix widgets we are examining: Tree and DirTree. The HList widget is a hierarchical list that uses the idea of paths to create the hierarchy it displays. You could also display a flat hierarchy and use HList as a type of Listbox that can have columns and column headings. Tree and DirTree are specialized versions of HList. DirTree is used to display a directory structure from a given starting point. All three of the widgets use display items.
The simplest way to use the HList widget is similar to a Listbox or TList. Create it and then add items to it:
use Tk; use Tk::HList; my $mw = MainWindow->new(-title => 'HList'); my $hlist = $mw->HList->pack; foreach (qw/one two three four five/) { $hlist->add($_, -text => $_); } MainLoop;
Looking at this example, it isn’t obvious at all that you can
have display items or styles with an HList. The only
non-self-explanatory item (given that you understand Listbox) is the
first argument to the add
method, which is a path.
Since this example doesn’t take advantage of any of the special
hierarchical features of the HList, we’re not going to bother
showing a screenshot yet.
Just like a Listbox, the HList contains a list of entries. Each time
you call the add
method, you create another entry
in the list. Each entry can contain one or more display items. If you
want more than one display item with each entry, use the
-columns
option. Unlike TList, which automatically manages ...
Get Mastering Perl/Tk now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.