Advertisement
Carrfamily

Untitled

Apr 29th, 2024
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. import os
  2. import tkinter as tk
  3. from PIL import Image, ImageTk
  4.  
  5. def display_images(folder_path, image_files):
  6. if not image_files:
  7. print("No more images to display.")
  8. return
  9.  
  10. image_file = image_files.pop(0)
  11. image_path = os.path.join(folder_path, image_file)
  12.  
  13. image = Image.open(image_path)
  14. photo = ImageTk.PhotoImage(image)
  15.  
  16. if "label" in window.__dict__:
  17. # Destroy the previous label
  18. window.label.destroy()
  19.  
  20. # Create a new label to display the current image
  21. window.label = tk.Label(window, image=photo)
  22. window.label.photo = photo
  23. window.label.pack()
  24.  
  25. # Schedule the next image after 15 seconds
  26. window.after(1500, lambda: display_images(folder_path, image_files))
  27.  
  28. def start_image_viewer(folder_path):
  29. image_files = [f for f in os.listdir(folder_path) if f.endswith(".jpg")]
  30. display_images(folder_path, image_files)
  31.  
  32. window = tk.Tk()
  33. window.title("Image Viewer")
  34. start_image_viewer("c:/Users/Tim Carr/Pictures/_Folks")
  35. window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement