在Tkinter中调整PIL中的图片大小
我目前正在使用PIL在Tkinter中显示图像。我想临时调整这些图像的大小,以便可以更轻松地查看它们。我该怎么办?
片段:
self.pw.pic = ImageTk.PhotoImage(Image.open(self.pic_file))self.pw.pic_label = TK.Label(self.pw , image=self.pw.pic,borderwidth=0)
self.pw.pic_label.grid(column=0,row=0)
回答:
这就是我所做的,并且效果很好…
image = Image.open(Image_Location)image = image.resize((250, 250), Image.ANTIALIAS) ## The (250, 250) is (height, width)
self.pw.pic = ImageTk.PhotoImage(image)
你去了:)
编辑:
这是我的进口声明:
from Tkinter import *import tkFont
from PIL import Image
这是我改编自此示例的完整工作代码:
im_temp = Image.open(Image_Location)im_temp = im_temp.resize((250, 250), Image.ANTIALIAS)
im_temp.save("ArtWrk.ppm", "ppm") ## The only reason I included this was to convert
## The image into a format that Tkinter woulden't complain about
self.photo = PhotoImage(file="ArtWrk.ppm") ## Open the image as a tkinter.PhotoImage class()
self.Artwork.destroy() ## Erase the last drawn picture (in the program the picture I used was changing)
self.Artwork = Label(self.frame, image=self.photo) ## Sets the image too the label
self.Artwork.photo = self.photo ## Make the image actually display (If I don't include this it won't display an image)
self.Artwork.pack() ## Repack the image
这是PhotoImage类文档:http
://www.pythonware.com/library/tkinter/introduction/photoimage.htm
注意…在检查了ImageTK的PhotoImage类的pythonware文档后(这非常稀疏),我发现,如果您的代码片段比这有效,那么只要您导入PIL“
Image”库和PIL“ ImageTK”库, PIL和tkinter都是最新的。另一方面,我什至找不到“
ImageTK”模块的生命。您可以过帐进口商品吗?
以上是 在Tkinter中调整PIL中的图片大小 的全部内容, 来源链接: utcz.com/qa/413567.html