I have found the code to find the last file saved in a folder, but I need to open this file for x amount of time, then close it. Can this be done?
Here is the code I am using to find the latest .jpg
import glob
import os
list_of_files = glob.glob('/home/pi/webcam/*.jpg')
latest_file = max(list_of_files, key=os.path.getctime)
print latest_file
I have tried the following, the code runs but nothing happens:
from PIL import Image
import glob
import os
list_of_files = glob.glob('/path/to/folder/*.jpg')
latest_file = max(list_of_files, key=os.path.getctime)
img = Image.open(latest_file)
img.show()
I am trying to build this into booth.py
Here is my attempt so far (with below suggestions)
I found these codes on Stack Overflow
As it stands, your program is opening a window, starting to exit and closing the window. This probably happens faster than your operating system's window opening animation.
Try:
If this solves your problem, then great! If you want to make this a permanent thing, start a non-daemon thread with the
img.show()call that only exits when the created window is closed. (You can probably figure out how to do this... maybe. I can't!)The reason that
os.startfile(playlist)isn't working is thatos.startfileis a Windows-only feature. You're using Python 2, and the only sane reason I can think of for that is to control Raspberry Pi GPIO pins; it won't be available on that platform.