Python图像显示

标签 python image

我如何创建一个 python 脚本来运行 mac 目录中的图像 (1.jpeg-n.jpeg) 并在浏览器中或通过另一个 python 程序显示它们?

我是否将文件导入 python 并在浏览器中显示? 我是否提取文件名 1、2、3、4、5 并将其添加到列表中,然后将其提供给调用浏览器并显示的另一个函数?

任何帮助都会很棒。

谢谢!

最佳答案

为此目的使用 Tkinter 和 PIL 非常简单。将 muskies 示例添加到来自 this thread 的信息中包含 this example :

# use a Tkinter label as a panel/frame with a background image
# note that Tkinter only reads gif and ppm images
# use the Python Image Library (PIL) for other image formats
# free from [url]http://www.pythonware.com/products/pil/index.htm[/url]
# give Tkinter a namespace to avoid conflicts with PIL
# (they both have a class named Image)

import Tkinter as tk
from PIL import Image, ImageTk

root = tk.Tk()
root.title('background image')

# pick an image file you have .bmp  .jpg  .gif.  .png
# load the file and covert it to a Tkinter image object
imageFile = "Flowers.jpg"
image1 = ImageTk.PhotoImage(Image.open(imageFile))

# get the image size
w = image1.width()
h = image1.height()

# position coordinates of root 'upper left corner'
x = 0
y = 0

# make the root window the size of the image
root.geometry("%dx%d+%d+%d" % (w, h, x, y))

# root has no image argument, so use a label as a panel
panel1 = tk.Label(root, image=image1)
panel1.pack(side='top', fill='both', expand='yes')

# put a button on the image panel to test it
button2 = tk.Button(panel1, text='button2')
button2.pack(side='top')

# save the panel's image from 'garbage collection'
panel1.image = image1

# start the event loop
root.mainloop()

当然,如果您更熟悉其他 GUI,请继续修改示例,这不会花太多时间。

关于Python图像显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3166221/

相关文章:

python - 如何使用 python Pandas 减去行?

Python交集出现顺序不一致

python - 如何仅抓取同一类中的某些标签?

java - JButton 图像渲染很糟糕

image - 谷歌流量和 CDN

python - 在 Keras 训练模型图像输入中选择特定的一组 RGB channel

python - 我可以向 pytest 套件添加 ini 样式配置吗?

python - 如何使用列变压器对多列进行编码?

javascript - extjs 在 TreePanel 中加载图像