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