无法创建带有图像“pyimage1”的图标照片
我真的不知道这行不通。由于这是一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论