我正在尝试在Tkinter窗口中显示PGM图像,但是我一直收到“无法识别图像文件中的数据”的错误。我的代码出问题了吗?
import tkinter as tk
from tkinter import filedialog
from tkinter import *
from tkinter import PhotoImage
def browse_file(self):
path = filedialog.askopenfilename()
if len(path) > 0:
photo = tk.PhotoImage(file=path)
cv = tk.Canvas()
cv.pack(side='top', fill='both', expand='yes')
cv.create_image(10, 10, image=photo, anchor='nw')