I have a program with a Tkinter window and I want to set an icon for the window. I use this code:window.iconbitmap(os.path.dirname(os.path.abspath(__file__))+"/icon.png")
but the following error is thrown:
Traceback (most recent call last):
File "myprogram.py", line 241, in <module>
window.iconbitmap(os.path.dirname(os.path.abspath(__file__))+"/icon.png")
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1591, in wm_iconbitmap
return self.tk.call('wm', 'iconbitmap', self._w, bitmap)
_tkinter.TclError: bitmap "/home/guest/documents/myprogramdir/icon.png" not defined
I think it is because I have the icon file in the same directory with the rest of my code. But that's how I want it to be. Is there a solution?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…