小编San*_*eer的帖子

Linux 上的 Python 3.6 tkinter 窗口图标错误

我正在从《Python GUI 编程手册》学习 Python GUI。某项任务要求我通过将以下代码添加到我的配方中来更改窗口图标:

# Change the main windows icon
win.iconbitmap(r'C:\Python34\DLLs\pyc.ico')
Run Code Online (Sandbox Code Playgroud)

由于我使用的是 Linux,因此我必须将路径更改为/home/user/test.ico. 阅读类似的问题后,我知道这.ico仅适用于Windows。我尝试过.gif,但这也不起作用。我尝试过的现有SO文章: tkinter TclError:读取位图文件时出错 在我的python Tk基础应用程序中设置应用程序图标(在Ubuntu上) tkinter.TclError:图像“pyimage3”不存在

所有这三个都没有帮助。我收到以下每个错误:

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, …
Run Code Online (Sandbox Code Playgroud)

python linux tkinter python-3.x

5
推荐指数
1
解决办法
4785
查看次数

标签 统计

linux ×1

python ×1

python-3.x ×1

tkinter ×1