PhotoImage zoom

问题描述 投票:0回答:1

我正在尝试放大图像并使用以下代码显示它

import tkinter as tk
from PIL import Image as PIL_image, ImageTk as PIL_imagetk

window = tk.Tk()

img1 = PIL_imagetk.PhotoImage(file="C:\\Two.jpg")
img1 = img1.zoom(2)

window.mainloop()

但是python说AttributeError: 'PhotoImage' object has no attribute 'zoom'。这里有相关帖子的评论:Image resize under PhotoImage上面写着“ PIL的PhotoImage无法实现Tkinter的PhotoImage缩放(以及其他一些方法)”。

我认为这意味着我需要将其他内容导入到我的代码中,但是我不确定是什么。任何帮助都会很棒!

python tkinter zoom photoimage
1个回答
0
投票

img1没有方法zoom,但是img1._PhotoImage__photo有。因此,只需将代码更改为:

© www.soinside.com 2019 - 2024. All rights reserved.