![](/img/trans.png)
[英]How can I resize an image without using .resize() in python PIL
[英]How can i resize images in Tkinter using PIL module
我得到了這個代碼,我得到了這個錯誤: AttributeError: 'PhotoImage' object has no attribute 'resize' 我也試過rgrapg = Image.open("risinggrap.jpg")
我得到這個錯誤:_tkinter.TclError: image " "不存在
rgraph = ImageTk.PhotoImage(Image.open("risinggrap.jpg"))
rgraph = rgraph.resize((200,250),Image.ANTIALIAS)
photoLabe = Label(x, image=rgraph)```
您需要先加載圖像,調整其大小,然后將其投射到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()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.