可能是图片路径不正确或者图片格式不支持导致的问题。请确认图片路径是否正确,图片格式是否为Tkinter支持的格式(如.gif)。
以下是修改后的例程:
import tkinter as tk
root = tk.Tk()
root.geometry("400x300")
root.title("My Image Viewer")
image = tk.PhotoImage(file=r"path/to/your/image.png")
label = tk.Label(root, image=image)
label.pack()
root.mainloop()
其中,将file
参数修改为正确的图片路径即可。