Adding Icon To Tkinter Window - Followup

Christian Gollwitzer auriocus at gmx.de
Sat Mar 5 13:36:19 EST 2016


Am 05.03.16 um 19:10 schrieb Wildman:
> On Sat, 05 Mar 2016 10:47:09 -0600, Wildman wrote:
>
>> Anybody have the correct method of adding an icon to a
>> window?  I have found several code examples on the web
>> but they all result in an error.  Thanks.
>
> I found this and it works in Linux but only with black
> and white xbm images (I would prefer color):
>
>      root.wm_iconbitmap('@myicon.xbm')

iconphoto is the newer API for color icons. I am a bit surprised that it 
is not wrapped in Tkinter, which is odd. You can still call it via eval:

import Tkinter
from Tkinter import Tk
root = Tk()
img = Tkinter.Image("photo", file="appicon.gif")
root.call('wm','iconphoto',root._w,img)


If you Tk is recent enough (8.6, you can find out by doing 
root.eval('info patchlevel')), you can use .png files in addition to 
.gif. If you need to read other image files, look into PIL and ImageTk.

	Christian




More information about the Python-list mailing list