Display Items

One of the things we gain when using Tix widgets is the ability to create a display item and then add it to a Tix widget for display. Display items are all rectangular, and the container widget manipulates those rectangles with little regard to anything other than the size of the rectangles and the order in which to display them.

There are four different types of items you can use in Tix widgets: text, imagetext, image, and window. A text item displays only text. An imagetext item can display both an image and text, or only an image, or only text. An image item displays only an image, and a window is another widget.

When creating each item in our TList, we specify the type using the -itemtype option:

$tl = $mw->TList->pack(-expand => 1, -fill => 'both');
foreach my $i (0..19) { 
  $tl->insert('end', -itemtype => 'text', -text => "Display Item #$i");
}

In Figure 18-1, we see there are 20 different display items inserted. Each has an item type of 'text'.

A TList widget showing display items

Figure 18-1. A TList widget showing display items

Now let’s change our example to show different item types:

$tl = $mw->TList->pack(-expand => 1, -fill => 'both'); my $image = $mw->Getimage('folder'); foreach my $i (0..4) { $tl->insert('end', -itemtype => 'text', -text => "text Item #$i"); $tl->insert('end', -itemtype => 'imagetext', -text => "imagetext item #$i", -image => $image); my $b = $tl->Button(-text => "Window ...

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.