一、描述 报错:couldn't recognize data in image file 代码: 1 2 3 4 5 6 7 8 9 10 11 fromtkinterimport* root=Tk() theLabel=Label(root,text="dog",justify=LEFT,padx=10) theLabel.pack(side=LEFT) photo=PhotoImage(file="D:/PythonProject/dog.jpg") imgLabel=Label(root,image=photo) img...
python报错_couldntrecognizedatainimagefile ⼀、描述 报错:couldn't recognize data in image file 代码:from tkinter import * root = Tk()theLabel = Label(root,text="dog",justify=LEFT,padx=10)theLabel.pack(side=LEFT)photo = PhotoImage(file="D:/PythonProject/dog.jpg")imgLabel = Label(root...
在用Python创建画布canvas,并在画布上导入图像时报错:“_tkinter.TclError: couldn't recognize data in image file "F:\Python\test\a.gif"” 用tkinter只能装入GIF图片,也就是扩展名是.gif的图片文件,想要显示其他类型的图片,如png或jpg,需要用到其它模块 defcanvas_test():importtkinter window=tkinter.Tk()...
如果想用 ".jpg"文件格式,直接用上面的代码,会报“couldn’t recognize data in image file "bm=PhotoImage(file=r’D:\a\aa.jpg’)"错误。 而且直接修改图片后缀为.gif格式也会出现这样的问题,修改方法只能从根本上修改如下(用ImageTK) gif文件以及png文件可以借助PhotoImage()方法。这是Tkinter方法, 这意味...
_tkinter.TclError: couldn't recognize data in image file "C:\Users\Administrator\Desktop\frame_0001.png" 唯有借助PIL实现: image_file = tk.PhotoImage(file=r'C:\Users\Administrator\Desktop\frame_0001.png') image = canvas.create_image(0, 0, anchor='n', image=image_file) # 改为 from PIL...
# 如下会报错:couldn't recognize data in image file "img.jpg" # 报错翻译:无法识别图像文件“img.jpg”中的数据 photo = tkinter.PhotoImage(file="img.jpg") tkinter.Label(master=root,image=photo).grid(row=0, column=0) root.mainloop() ...
用你的图片地址替换“path/to/image.png”即可。但实际测试时发现有的 png 图片可以正常展示,但是有的却不能,会报如下错误: 复制 _tkinter.TclError: couldn't recognizedatainimagefile"images/beutiful_girl.jpg" 1. 网上说 Tkinter 只支持 gif 格式的图片,要加载 png 或 jpg 格式的图片应该用 PIL 包的 ...
_tkinter.TclError: couldn’t recognize data in image file 2 .关于base64 大家看到我没有加载图片,而是通过base64提前转码好二进制文件后,再进行导入,这样我们打包的exe在使用时,就无需附带一个图片文件了! 1importbase6423withopen('清风Python.gif','rb')asf:4data=f.read()5img=base64.b64encode(data...
_tkinter.TclError: couldn’t recognize data in image file 2 关于base64 大家看到我没有加载图片,而是通过base64提前转码好二进制文件后,再进行导入,这样我们打包的exe在使用时,就无需附带一个图片文件了! 代码语言:javascript 代码运行次数:0 运行
_tkinter.TclError: couldn’t recognize data in image file 关于base64 大家看到我没有加载图片,而是通过base64提前转码好二进制文件后,再进行导入,这样我们打包的exe在使用时,就无需附带一个图片文件了! import base64 with open('demo.gif','rb') as f: data = f.read() img = base64.b64encode(dat...