Version 6 of How do I give my application a color icon

Updated 2003-11-06 16:16:07

On the one hand, one has to understand that this is NOT possible to do successfully across all platforms and window managers.

There are just too many variations.

Howev, here is something to attempt. Note that out of the box, Tk accepts only three image file formats - GIF, PGM, and PPM.

If you want to use something other than that, take a look at Img, which adds additional photo image types.


 # Sample created by Larry W. Virden, with the kind assistance of
 #    Donal K. Fellows
 # Date: Nov 6, 2002

 package require Tcl
 package require Tk

 if { $argc != 1 } {
        puts stderr "$argv0 gif_pathname"
        exit
 }
 set icon_pathname [lindex $argv 0]

 set i [image create photo .i1 -format gif -file $icon_pathname ]

 set b [button .b1 -text hello]

 pack $b
 toplevel .icon;pack [label .icon.l -image $i]
 wm iconwindow . .icon

You may need to add the following to this code:

  wm withdraw .
  wm state . normal

to force the window manager to recognize the change in icon.


Geoff Battye mentions on comp.lang.tcl that the above code results in a color icon showing up on the desktop with window managers like fvwm (and lv did the above work under cde). However, it didn't result in KDE showing a color icon in its title bar, alt-switching panel or its taskbar. So, MGS developed the code documented in KDE window icons to solve that need.


See also:


Category Graphics | Category Porting