使用Tkinter命令"iconbitmap"来完成.设置窗口图标 [英] Using Tkinter command "iconbitmap" to set window icon
问题描述
我有一个带有Tkinter窗口的程序,我想为该窗口设置一个图标.我对此进行了编码:okno.iconbitmap(os.path.dirname(os.path.abspath(__file__))+"/icon.png")
但它写道:
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?
推荐答案
假设在Windows操作系统中引发了此错误,问题在于iconbitmap
在Windows中似乎不支持png
文件类型.请使用.ico
文件类型.此网络工具对我来说非常出色- https://iconverticons.com/online/.对于Linux操作系统,请使用xbm
文件类型.
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-下次问问题时,请提供相关详细信息.例如:出现此错误的操作系统的名称和版本.
PS- Please provide relevant details when asking questions next time. For example: name and version of OS where you got this error.
这篇关于使用Tkinter命令"iconbitmap"来完成.设置窗口图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!