Book HomeMastering Perl/TkSearch this book

17.6. The Pixmap Image Type

Applications often use pixmaps rather than bitmaps for their icon images, because pixmaps provide more than two colors. Here's how to do that:

my $pixmap = $mw->Pixmap(-file => 'Icon.xpm');
$mw->Icon(-image => $pixmap);

Pixmaps are plain text, so they easily embed in your Perl/Tk program. The Pixmap constructor has only one other option, -data, for just such a case. The following Pixmap has four RGB colors: white, black, tabby-orange, and green, represented by the characters " ", ., X, and o, respectively.

my $pixmap_data = <<'end-of-x11-pixmap-data';
/* XPM */
static char * Icon_xpm[] = {
"32 32 4 1",
"     c #FFFFFFFFFFFF",
".    c #000000000000",
"X    c #FFFFBDBD0000",
"o    c #0000FFFF0000",
"                                ",
"       ..                ..     ",
"      ...               ...     ",
"      .X..             .....    ",
"     ..XX..            ......   ",
"     .X..X.           ...X...   ",
"    ..X.X.X. .......  .......   ",
"    .X.XXX....XXXXX...........  ",
"   ..X.X..XXXXXXXXXXXX........  ",
"   .XX...XXXXXXXXXXXXXXX......  ",
"   .X..XXXXXXXXXXXXXXXXXX.....  ",
"   ...XXXXXXXXXXXXXXXXXXXX....  ",
"   .XXXXXXXXXXXXXXXXXXXXXXX...  ",
"   .XXXXXXXXXXXXXXXXXXXXXXXXX.  ",
"  ..XXX.....XXXXXXX.....XXXXX.  ",
"  .XXX.ooooo.XXXXX.ooooo.XXXX.  ",
"  .XX.ooooo.o.XXX.o.ooooo.XXX.  ",
" ..XX.ooooooo.XXX.ooooooo.XXX.  ",
" .XXXX.ooooo.XXXXX.ooooo.XXXXX. ",
" .XXXXX.....XXXXXXX.....XXXXXX. ",
" .XXXXXXXXXXXXXXXXXXXXXXXXXXXX. ",
" .XXXXXXXXXXXXX.XXXXXXXXXXXXXX. ",
" .XXXXXXXXXXXXXXXXXXXXXXXXXXXX. ",
"..XXX..XXXXXXXXXXXXXXXXXXXXXXXX.",
".XXX.XX.XXXXXXXXXXXXXXXX...XXX..",
".XX.XX.XXXXXXXXXXXXXXXX..XX.XX..",
".XX.X.X.XXXXX.XXX.XXXXX.X.XXX...",
".XXXX.X.XXXXXX...XXXXXXX.X.XX.X.",
"..XXX.X.XXXXXXXXXXXXXXXX.X.XX.X.",
".X.XXXXXXXXXXXXXXXXXXXXX.XXX.XX.",
".XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.",
".XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX."};
end-of-x11-pixmap-data

$mw->Icon(-image => $mw->Pixmap(-data => $pixmap_data));


Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.