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

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

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