# changing the default icon in Tkinter programs

from Tkinter import *

# create the form and a label
form1 = Tk()
lbl1 = Label(form1, text='Changing the Tk icon is very easy!')
lbl1.pack(expand=YES, fill=BOTH)

# change the form/frame icon, use an icon file you have ...
form1.wm_iconbitmap('D:/Python24/py.ico')
form1.wm_title('New Icon')

# run it ...
form1.mainloop()
3
Contributors
4
Replies
7
Views
11 Years
Discussion Span
Last Post by The-IT
0

I tried to use this code to replace the "tk" icon on a script, but the icon never changed. My icon size is 14x14, and the snippet where I put the code is below...

...
class GUIFramework(Frame):
    """This is the GUI"""
    
    def __init__(self,master=None):
        """Initialize yourself"""
        self.root = Tk()
        
        """Initialise the base class"""
        Frame.__init__(self,master)
        
        """Set the Window Title"""
        self.master.wm_iconbitmap('rssicon.ico')
        self.master.title('RSS Reader')
...
0

The closest I could get was a 16x16 'rssicon.ico' and it worked fine using your code, even with that somewhat mysterious self.master

Edited by vegaseat: n/a

0

Sure enough, as soon as I resized it to 16x16 the icon showed up. Thank you for your help.

0

this is probably a reallllyyyy old post but, im having trouble with changeing the icon.

from Tkinter import *
root = Tk()
root.wm_iconbitmap('icon.ico')
root.mainloop()

and i get this error:

Traceback (most recent call last):
  File "file", line 3, in <module>
    root.wm_iconbitmap('icon.ico')
  File "/usr/lib/python2.5/lib-tk/Tkinter.py", line 1529, in wm_iconbitmap
    return self.tk.call('wm', 'iconbitmap', self._w, bitmap)
_tkinter.TclError: bitmap "icon.ico" not defined

the image size is 16x15

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.