无法创建带有图像“pyimage1”的图标照片

发布于 2025-01-11 18:05:40 字数 986 浏览 0 评论 0原文

我真的不知道这行不通。由于这是一个 tkinter 错误,我不知道如何修复它。需要帮助。

代码:

from urllib import request
from tkinter import *
import urllib
import base64

user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36"
url = "https://redstoner.me/downloads/gigashitfiles/gigashit.ico"
headers = {"User-Agent" : user_agent,} 
request = urllib.request.Request(url,None,headers)
response = urllib.request.urlopen(request)
response.close()
b64pic = base64.encodebytes(response.read())
image = PhotoImage(data=b64pic)
window.iconphoto(True, image)

输出:

 File"myfilepath", line 19, in <module>
    window.iconphoto(True, image)
  File "C:\Users\panag\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 2154, in wm_iconphoto
    self.tk.call('wm', 'iconphoto', self._w, "-default", *args)
_tkinter.TclError: failed to create an iconphoto with image "pyimage1"

I really have no idea with this isn't working. Since it's a tkinter error, I have no idea how to fix it. Help is needed.

Code:

from urllib import request
from tkinter import *
import urllib
import base64

user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36"
url = "https://redstoner.me/downloads/gigashitfiles/gigashit.ico"
headers = {"User-Agent" : user_agent,} 
request = urllib.request.Request(url,None,headers)
response = urllib.request.urlopen(request)
response.close()
b64pic = base64.encodebytes(response.read())
image = PhotoImage(data=b64pic)
window.iconphoto(True, image)

Output:

 File"myfilepath", line 19, in <module>
    window.iconphoto(True, image)
  File "C:\Users\panag\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 2154, in wm_iconphoto
    self.tk.call('wm', 'iconphoto', self._w, "-default", *args)
_tkinter.TclError: failed to create an iconphoto with image "pyimage1"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文