Python图像显示

Mac*_*hon 2 python image

如何在mac上的目录中创建运行图像(1.jpeg-n.jpeg)的python脚本,并在浏览器中显示或通过其他python程序显示?

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

任何帮助都会很棒.

谢谢!

Way*_*ner 5

为此目的使用Tkinter和PIL非常简单.将muskies示例添加到包含此示例的此线程的信息中:

# 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()
Run Code Online (Sandbox Code Playgroud)

当然,如果你对另一个GUI更熟悉,那么继续调整这个例子,它不应该花费太多.