标题在使用PhotoImage方法打开jpg文件失败
我琢磨了好久都没有找到具体的错误在哪里,我以为是我的代码逻辑问题,或者是其他的原因。
最后才考虑到是因为PhotoImage方法不支持打开jpg格式,然后去官网查看之后才明白,PhotoImage方法打开的文件格式有哪些。
filename = fd.askopenfilename(filetypes=[("PNG图片", "*.png"),('gif图片','*.gif')]) image = tk.PhotoImage(file=filename) canvas.create_image((0, 0), image=image, anchor="nw")
格式主要有:PGM, PPM, GIF, PNG 这四种。