O'Reilly logo

Mastering Perl/Tk by Nancy Walsh, Stephen Lidie

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required