我得到了這段代碼,但出現了這個錯誤: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
提交
取消