我得到了这段代码,但出现了这个错误:AttributeError: 'PhotoImage' object has no attribute 'resize rgrapg = Image.open("risinggrap.jpg")' rgraph = ImageTk.PhotoImage(Image.open("risinggrap.jpg"))
rgraph = rgraph.resize((200,250),Image.ANTIALIAS)
photoLabe = Label(x, image=rgraph)```
1 回答
呼唤远方
TA贡献1856条经验 获得超11个赞
您需要先加载图像,调整大小,然后将其转换为ImageTk.PhotoImage. 这是一个像这样的工作示例:
import tkinter as tk
from PIL import Image, ImageTk
x = tk.Tk()
# 1. load image
image = Image.open("risinggrap.jpg")
# 2. resize it
image = image.resize((200, 250), Image.ANTIALIAS)
# 3. cast it into ImageTk.PhotoImage
rgraph = ImageTk.PhotoImage(image)
photoLabel = tk.Label(x, image = rgraph)
photoLabel.pack(side = "bottom", fill = "both", expand = "yes")
x.mainloop()
添加回答
举报
0/150
提交
取消