3

I was looking at Removing the TK icon on a Tkinter window but when trying to duplicate the code I encountered an error. Below is the code and error

from Tkinter import *
import Image, ImageTk
import sys

def quit(self):
    self.root.destroy()

root = Tk()
root.title("GUI program")
root.iconbitmap(default="C:\easy\Pics\ILC.ico")
im = Image.open("C:\easy\Pics\No-Image-Available.jpg")

image1 = ImageTk.PhotoImage(im)

# root has no image argument, so use a label as a panel
panel1 = Label(root, image=image1)
panel1.pack(side='top', fill='both', expand='yes')

root.mainloop()

Here is a copy of the error:

Traceback (most recent call last):
File "C:\easy\python\IPcam\test_image.py", line 11, in <module>
root.iconbitmap(default="C:\\easy\\Pics\\transparent.ico")
File "C:\Python25\lib\lib-tk\Tkinter.py", line 1524, in wm_iconbitmap
return self.tk.call('wm', 'iconbitmap', self._w, '-default', default)
TclError: bitmap "C:\easy\Pics\transparent.ico" not defined

I followed all of the steps. Any ideas?

Community
  • 1
  • 1
santhon88
  • 62
  • 2
  • 6

2 Answers2

0

I've executed your example and it works ok for me.

I can simulate your error when I use a wrong path for the ico file. Did you double-check that "C:\\easy\\Pics\\transparent.ico" exists?

There is also two potential mistakes in your code:

1) Use '\\' or a raw string the path:

im = Image.open(r"C:\easy\Pics\No-Image-Available.jpg")

2) Don't forget to run the tk main loop at the end

root.mainloop()

I hope it helps

luc
  • 41,928
  • 25
  • 127
  • 172
  • luc, The only issue I am having deals with the icon. The ico file exists, I created it using the recommended website [link](http://www.rw-designer.com/online_icon_maker.php).The image works fine and in other programs I use has root.mainloop(). I just pasted code that demonstrated the error. – santhon88 Dec 10 '12 at 13:43
  • Ok, so it just typo in the code in the question. You may have to fix that if you want people can try to run your sample easily. Regarding the issue, did you try to put the ico in the app folder and to access it directly? – luc Dec 10 '12 at 14:40
  • I did, no change in error. Using command prompt I was able to navigate to the directory and open the icon. So the path is fine. I'm wondering if the icon image itself needs to be created from a picture with a different format – santhon88 Dec 10 '12 at 19:29
0

Try replacing the '\' characters with '/' in the file paths. '\' signifies a string literal and can through off quotes.

hellowill89
  • 1,538
  • 2
  • 15
  • 26