If you're like me and most other Perl Tk programmers, you've no doubt asked yourself from time to time how in the world can you use transparent pixels in your Tk window's icon? Using a simple GIF or PNG image with transparent pixels doesn't cut it because the transparent parts show up as a solid color anyway. So how is it done?
The answer: you need to create an X BitMap Image (XBM) file and use it as a mask for your window's icon. Fortunately, this is easy to do.
Some image editing programs can save your images as XBM format already. I recommend The GIMP.
1. Open your icon image (we'll say that it's called appicon.png) in The GIMP.
2. Click "File / Save As". Make sure you select the file type to be "X BitMap Image (xbm)".
It might warn you about how you have to export the image first. Go ahead and click "Export" and let it do it for you. Then the XBM window will come up to ask you for some options for your image.
3. Make sure that "Write extra mask file" is checked. This is the whole purpose of exporting it into this format to begin with.
4. Go ahead and save it. It should create two files: appicon.xbm and appicon_mask.xbm in this case. We're only interested in the mask file.
5. Place the mask file in a location where your Perl script can get to it. Now, you simply call iconmask() on your MainWindow and point it in the right direction: