Tinkering with the Tk Icon (Python)

vegaseat 0 Tallied Votes 1K Views Share

Tired of the Tk icon in the corner of the form. It's easy to replace with any fancy icon you have. Here is the code ...

# 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()
chrlshrdy 0 Newbie Poster

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')
...
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

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

chrlshrdy 0 Newbie Poster

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

The-IT 0 Newbie Poster

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.