標題在使用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 這四種。