0
我正在學習Python GUI編程手冊中的Python GUI。某些任務要求我加入以下代碼,我的食譜改變窗口的圖標:Python 3.6在Linux上的tkinter窗口圖標錯誤
# Change the main windows icon
win.iconbitmap(r'C:\Python34\DLLs\pyc.ico')
由於我使用Linux,我有我的路徑更改爲/home/user/test.ico
。在閱讀過類似的問題後,我知道.ico
只是Windows。我試過.gif
,但那也行不通。現有的SO文章我想: tkinter TclError: error reading bitmap file Setting Application icon in my python Tk base application (On Ubuntu) tkinter.TclError: image "pyimage3" doesn't exist
所有的這三人是無益的。我與每個以下錯誤:
In [3]: runfile('/home/bhedia/untitled1.py', wdir='/home/bhedia')
Traceback (most recent call last):
File "<ipython-input-3-17a671578909>", line 1, in <module>
runfile('/home/bhedia/untitled1.py', wdir='/home/bhedia')
File "/home/bhedia/anaconda3/envs/mitx/lib/python3.5/site-packages/spyder/utils/site/sitecustomize.py", line 880, in runfile
execfile(filename, namespace)
File "/home/bhedia/anaconda3/envs/mitx/lib/python3.5/site-packages/spyder/utils/site/sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "/home/bhedia/untitled1.py", line 58, in <module>
img = tk.PhotoImage(file='test.ico')
File "/home/bhedia/anaconda3/envs/mitx/lib/python3.5/tkinter/__init__.py", line 3403, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "/home/bhedia/anaconda3/envs/mitx/lib/python3.5/tkinter/__init__.py", line 3359, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
TclError: couldn't recognize data in image file "test.ico"
In [4]: runfile('/home/bhedia/untitled1.py', wdir='/home/bhedia')
Traceback (most recent call last):
File "<ipython-input-4-17a671578909>", line 1, in <module>
runfile('/home/bhedia/untitled1.py', wdir='/home/bhedia')
File "/home/bhedia/anaconda3/envs/mitx/lib/python3.5/site-packages/spyder/utils/site/sitecustomize.py", line 880, in runfile
execfile(filename, namespace)
File "/home/bhedia/anaconda3/envs/mitx/lib/python3.5/site-packages/spyder/utils/site/sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "/home/bhedia/untitled1.py", line 59, in <module>
root.tk.call('wm','iconphoto',root._w,img)
TclError: can't use "pyimage2" as iconphoto: not a photo image
所以,我不知道如何在Linux上使用的Tkinter庫時改變我的窗口的圖標。
在[3]上的錯誤說,你正在使用你不應該的ico文件。您應該使用.xbm fil,如您在[第一個鏈接](https://stackoverflow.com/questions/11176638/tkinter-tclerror-error-reading-bitmap-file)中所述。 – Lafexlos