python - 使用 Tkinter 显示一系列 PIL 图像

标签 python tkinter python-imaging-library

我正在循环中生成 PIL Image 对象。我想显示这些是用 Tkinter 生成的。

我该如何去做呢?

最佳答案

您可以创建一个包含LabelTkInter窗口,每次要更改图像时,创建一个新的ImageTk.PhotoImage并将标签的 image 属性设置为新创建的 PhotoImage。示例:

import Tkinter
import Image, ImageTk
root = Tkinter.Tk()
label = Tkinter.Label(root)
label.pack()
def change_image(image):
    photoimage = ImageTk.PhotoImage(image)
    label.config(image=photoimage)
root.mainloop()

每当您需要更改图像时,请调用change_image()

关于python - 使用 Tkinter 显示一系列 PIL 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11239635/

相关文章:

python - 替代 tkinter.dooneevent

python - 从列表中选择特定项目

python - 登录并通过 if 显示菜单项

python - 将图像中的像素值替换为不同的值,但得到颜色值后,它是不同的

python - PIL : Create one-dimensional histogram of image color lightness?

python - 在 Python 中显示图像大小的正确方法是什么?

python - 更改默认的seaborn热图

python - Scipy 的 fmin 有时只粘在 inf 上

python - 在 Python 描述符中创建动态文档字符串

Python 函数中的变量?