该示例在画布上显示图像。
from PIL import Image, ImageTk
# From the PIL (Python Imaging Library) module, we import the Image and ImageTk modules.
self.img = Image.open("tatras.jpg")
self.tatras = ImageTk.PhotoImage(self.img)
# Tkinter does not support JPG images internally. As a workaround, we
# use the Image and ImageTk modules.
canvas = Canvas(self, width=self.img.size[0]+20, height=self.img.size[1]+20)
# We create the Canvas widget. It takes the size of the image into account. It is 20px wider and 20px higher than the actual image size.
canvas.create_image(10, 10, anchor=NW, image=self.tatras)