要在Tkinter的Label中显示图片,可以使用PhotoImage类来加载图片并将其赋值给Label的image属性。
以下是一个示例代码:
import tkinter as tk from tkinter import PhotoImage root = tk.Tk() # 加载图片 image = PhotoImage(file="example.png") # 在Label中显示图片 label = tk.Label(root, image=image) label.pack() root.mainloop()
在这个示例中,首先加载了名为"example.png"的图片,然后创建了一个Label并将图片赋值给它的image属性,最后将Label添加到主窗口中显示。确保在PhotoImage
中传入正确的图片路径。