Warm tip: This article is reproduced from serverfault.com, please click

Using Tkinter command "iconbitmap" to set window icon

发布于 2015-04-30 16:37:07

I have a program with Tkinter window and I want to set an icon for the window. I coded this:okno.iconbitmap(os.path.dirname(os.path.abspath(__file__))+"/icon.png") but it writes:

Traceback (most recent call last):
  File "Alchymist_lab.py", line 241, in <module>
    okno.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/lenka/documents/Alchymist_Lab/icon.png" not defined

and i know why: because i have the icon file in the same directory as my code. But i do want to have it in the same directory as my code. Is there a solution?

Questioner
Vítek Peterka
Viewed
0
Manavalan Gajapathy 2015-05-16 11:18:35

Assuming this error is thrown in Windows OS, problem is that iconbitmap does not seem to support png filetype in Windows. Use .ico filetype instead. This webtool works superb for me - https://iconverticons.com/online/. For Linux OS, use xbm filetype.

PS- Please provide relevant details when asking questions next time. For example: name and version of OS where you got this error.