I have several images which I would like to show the user with Python. The user should enter some description and then the next image should be shown.
This is my code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os, glob
from PIL import Image
path = '/home/moose/my/path/'
for infile in glob.glob( os.path.join(path, '*.png') ):
im = Image.open(infile)
im.show()
value = raw_input("Description: ")
# store and do some other stuff. Now the image-window should get closed
It is working, but the user has to close the image himself. Could I get python to close the image after the description has been entered?
I don’t need PIL. If you have another idea with another library / bash-program (with subprocess), it’ll be also fine.
The
showmethod “is mainly intended for debugging purposes” and spawns an external process for which you don’t get a handle, so you can’t kill it in a proper way.With PIL, you may want to use one of its GUI modules , such as
ImageTk,ImageQtorImageWin.Otherwise, just manually spawn an image viewer from Python with the
subprocessmodule: