在 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)
I'm currently using PIL to display images in Tkinter. I'd like to temporarily resize these images so that they can be viewed more easily. How can I go about this?
Snippet:
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这就是我所做的,它工作得很好...
你去:)
编辑:
这是我的导入语句:
这是我改编此示例的完整工作代码:
这里是 PhotoImage 类文档:http://www.pythonware.com/library/tkinter/introduction/photoimage.htm
笔记...
在检查了有关 ImageTK 的 PhotoImage 类的 pythonware 文档(非常稀疏)之后,我发现如果您的代码片段有效,那么只要您导入 PIL“Image”库和 PIL“ImageTK”库,并且 PIL 和tkinter 是最新的。另一方面,我什至找不到“ImageTK”模块的生命。你能发布你的进口吗?
Here's what I do and it works pretty well...
There you go :)
EDIT:
Here is my import statement:
And here is the complete working code I adapted this example from:
And here are the PhotoImage class docs: http://www.pythonware.com/library/tkinter/introduction/photoimage.htm
Note...
After checking the pythonware documentation on ImageTK's PhotoImage class (Which is very sparse) I appears that if your snippet works than this should as well as long as you import the PIL "Image" Library an the PIL "ImageTK" Library and that both PIL and tkinter are up-to-date. On another side-note I can't even find the "ImageTK" module life for the life of me. Could you post your imports?
如果您不想保存,可以尝试:
if you don't want save it you can try it:
最简单的方法可能是根据原始图像创建一个新图像,然后用较大的副本替换原始图像。为此,tk 图像有一个
copy
方法,可让您在制作副本时对原始图像进行缩放或二次采样。不幸的是,它只能让您以 2 倍进行缩放/子采样。the easiest might be to create a new image based on the original, then swap out the original with the larger copy. For that, a tk image has a
copy
method which lets you zoom or subsample the original image when making the copy. Unfortunately it only lets you zoom/subsample in factors of 2.