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

Updated 2003-09-07 02:41:00

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

See also:


Category Graphics | Category Porting