0

while doing this loop, I would like the image shown to be closed after entering the input, and for the next iteration it would be a repeated cycle for each image.

Currently, in the second iteration, two photos open to me in the next 3, etc.

app.py

i = 0
for file in os.listdir(path):
    process_list = []
    for proc in psutil.process_iter():
        process_list.append(proc)
    with Image.open(path + "/" + file) as img:
        img.show()
    kod = input("Insert code: ")
    for proc in psutil.process_iter():
        if not proc in process_list:
            proc.kill()
    os.rename(path + "/" + file,path + "/" + directory + "_{0:03}_".format(i) + kod + '.jpg')
    i+=1
  • Does this answer your question? [How can I close an image shown to the user with the Python Imaging Library?](https://stackoverflow.com/questions/6725099/how-can-i-close-an-image-shown-to-the-user-with-the-python-imaging-library) – zvi Oct 10 '20 at 18:20

1 Answers1

0

img.show() creates a display process, which can be killed using psutil as follows:

for proc in psutil.process_iter():
    if proc.name() == "display":
        proc.kill()
Abhinav Mathur
  • 7,791
  • 3
  • 10
  • 24