May-25-2017, 09:12 PM
I have a loop that opens and closes images.
I usually run my programs through IDLE or Jupyternotebook, but I could only find KeyPress readers (barring Tinker and GUIS which I haven't really studied yet) that work on the OS level. My OS is Windows 7.
Here is a sample of what I tried to do. I tried variations of this code using multiple while loops etc:
Looking for suggestions of a better way to do this.
Thank you.
from PIL import Image import time import subprocess for i in bio: p = subprocess.Popen(["C:\Program Files\IrfanView\i_view64.exe",'C:\\Users\Moondra\\Bioteck_charts\{}.png'.format(i)]) time.sleep(5) p.kill()As you can see the loop iterates every 5 seconds. I would like to pause this loop with "spacebar" if I see an image I would like to study more in detail, and then resume the loop once I press space bar again. I would also like to escape out of the entire loop if I press
ESC
I usually run my programs through IDLE or Jupyternotebook, but I could only find KeyPress readers (barring Tinker and GUIS which I haven't really studied yet) that work on the OS level. My OS is Windows 7.
Here is a sample of what I tried to do. I tried variations of this code using multiple while loops etc:
from PIL import Image import time import subprocess import pickle with open('Bioteck.pickle', 'rb') as file: bio = pickle.load(file) from msvcrt import getch key = ord(getch()) for i in bio: while key != 27: #escape key p = subprocess.Popen(["C:\Program Files\IrfanView\i_view64.exe",'C:\\Users\Moondra\\Bioteck_charts\{}.png'.format(i)]) time.sleep(5) p.kill() break if key == 32: #Space bar) raw_input() if key == 32: #kill p.kill() continue if key == 27: os._exit()However, pressing spacebar, just doesn't pause the loop. It just jumps to the next image in the loop.
Looking for suggestions of a better way to do this.
Thank you.