python_remote_access/Controller/image-viewer.py
2021-04-19 14:37:54 +01:00

45 lines
1.3 KiB
Python

#!/usr/bin/python3
#Displays a loop of all image files found by gather_files.py. Run that script first to populate your image db file. See README for python dependency installation hints.
import tkinter as tk
from PIL import ImageTk, Image
import os, random, time
#Loop through a new image every 4 seconds.
def update_image():
path = "screen.jpg"
try:
img = ImageTk.PhotoImage(Image.open(path).resize((800, 480)))
#Issue with image file, try another.
except Exception as e:
print("Error: " + str(e))
path = get_random_file()
img = ImageTk.PhotoImage(Image.open(path).resize((800, 480)))
panel.configure(image=img)
panel.image = img
window.after(100, update_image)
return
path = "screen.jpg"
window = tk.Tk()
#window.attributes("-fullscreen",True)
window.title("Photo Gallery")
window.geometry("800x480")
window.configure(background='black')
#Load an initial image onto the Label.
try:
img = ImageTk.PhotoImage(Image.open(path).resize((800, 480)))
#Issue with image file, try another.
except Exception as e:
print("Error: " + str(e))
path = "screen.jpg"
img = ImageTk.PhotoImage(Image.open(path).resize((800, 480)))
panel = tk.Label(window, image=img)
panel.pack(side="bottom", fill="both", expand="yes")
update_image()
window.mainloop()