The Compound Image Type

We can combine existing images, bitmap, and text characters to create a multiline mega-image called a Compound, which we then use just like any other image.

The first and third lines are vertical spacers, 10 pixels in height. The second line combines a bitmap, text, and an image separated by horizontal spacers. Although the components of a Compound have configurable foreground and background colors and can be justified and anchored in various ways, that’s really all there is to Compounds.

my $c = $b->Compound;

$c->Space(-height => 10);       # line 1

$c->Line;                          # line 2
$c->Space(-width => 10);
$c->Bitmap(-bitmap => 'hourglass', -foreground => 'red');
$c->Space(-width => 10);
$c->Text(-text => "Searching for ", -font => 'times 19');
$c->Image(-image => $b->Pixmap(-file => 'Icon.xpm'));
$c->Space(-width => 10);

$c->Line;                          # line 3
$c->Space(-height => 10);

These statements created the three-line Compound in Figure 17-15.

Combining a bitmap, text, spaces, and an image

Figure 17-15. Combining a bitmap, text, spaces, and an image

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.