Using Tkinter command “iconbitmap” to set window icon

末鹿安然 提交于 2019-12-25 03:39:29

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/29973246/using-tkinter-command-iconbitmap-to-set-window-icon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!