Version 18 of wm iconbitmap

Updated 2004-04-12 17:02:16

wm iconbitmap window ?bitmap?

If bitmap is specified, then it names a bitmap in the standard forms accepted by Tk (see the Tk_GetBitmap manual entry for details). This bitmap is passed to the window manager to be displayed in window 's icon, and the command returns an empty string. If an empty string is specified for bitmap, then any current icon bitmap is cancelled for window. If bitmap is specified then the command returns an empty string. Otherwise it returns the name of the current icon bitmap associated with window, or an empty string if window has no icon bitmap. On the Windows operating system, an additional flag is supported: wm iconbitmap window ?-default? ?image?. If the -default flag is given, the icon is applied to all toplevel windows (existing and future) to which no other specific icon has yet been applied. In addition to bitmap image types, any (name of a) file which contains a valid Windows icon is also accepted (usually .ico or .icr files). Tcl will first test if the files contains an icon, and if that fails, test for a bitmap. (Tcl Help, bold addition by RS)


Eric Brunel writes, on news:comp.lang.tcl ,

Since I just spent half an hour to figure out how this works, I thought someone might be interested. The exact syntax is:

 wm iconbitmap <window> <icoFileName>

and not:

 wm iconbitmap <window> @<icoFileName>

(the "regular" bitmap files required the "@" in front of them and the manual is a tad unclear on this point...).


HolgerJ: 2004-03-11 The above is _not_ true, neither for Tk8.3.2/Windows nor for Tk8.3.2/Linux. In both cases, leaving out the @ before the file name results in an error. On _both_ platforms, @filename.xbm sets the image and can be retrieved later by calling "wm iconbitmap ." without a new icon definition. Using .ico files results in an error, on _both_ platforms!

But it is also true that on _both_ platforms (MS Windows 2000 and Linux with IceWM) the icon does _not_ show. On Windows, the icon remains to be the Tk logo; on IceWM, the icons remains to be an X logo. Bad luck, no cigar! The changing of the icon does work with Tk8.4 on KDE3.1 (yes!), but not on IceWM. Since other apps (like Mozilla and xterm) have no problem setting their individual icons on IceWM, the fault has to be Tk's. Tk8.4.2 on Windows is also funny. Using an .ico file with the leading @ works fine, using an .xbm file gives wrong colors, but works. Leaving out the @ in front of the filename works with almost all kinds of files and uses the icon of the associated file type.

 wm iconbitmap . whateverfile.pdf

shows the PDF icon in your Tk app. Is this of much use? Maybe, but is it the expected behavior?

I also tried to create a bitmap using "image create bitmap bm1 -file filename.xbm" and use this later in a "wm iconbitmap . bm1", but the result is an error message 'bitmap bm1 not defined'. What to do next?


Therefore, typing

 wm iconbitmap . myicon.ico

(where myicon.ico can be either this relative name, or even a full pathname) results in Tk reading the file to determine whether it is an icon or a bitmap file.


Recently tclguy mentioned on comp.lang.tcl that a) the @ isn't required for Windows, but is for Unix and that b) windows requires .ico for the format of the file, while Unix requires .xbm formatted files.

While these differences do mean that you have to code different lines for Windows vs Unix, considering that wm is pretty platform/desktop specific that is going to have to be something one deals with.


Question 1 : what does one do if they want to use on Windows a .bmp file for an icon?

Vince I think in Tcl 8.4, some uses with a Tk bitmap do work.

Question 2 : what does one do if one wants to make the icon in Tcl itself, e.g. use a string as input for the icon ? -

RS: Oh yes - if we had a "gateway" to photo images, we could use base64 encoded data, or strimjes (see strimj - string image routines), or files - a grand unification.

So another weekend project is born? RS: Hmm.. no promises - I have no ways of fiddling with the core at home. Fun projects are about sitting in the balcony, scribbling a few lines of Tcl, and late in the evening they all prove to work ;-)


Boltar I'm using Tcl/Tk 8.4.6.0 on a Windows2000 system. On Windows many applications store their icon inside the executive file. So typing:

 wm iconbitmap . test.exe

will return an error. But if you type:

 wm iconbitmap . [wm iconbitmap .]

 wm iconbitmap . test.exe

or

 wm iconbitmap . [wm iconbitmap .]

 wm iconbitmap . -default test.exe

you'll see the icon of the executive.


Tk Syntax Help - Category Command