Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- # Using Python 3.5.4
- import tkinter as Tk
- import os
- from PIL import Image, ImageTk
- import random
- root = Tk.Tk()
- ############## PARAMETER ##############
- # Change the directory that is going to be scanned
- path = r"C:\PATH\TO\THE\PICTURES\FOLDER"
- #######################################
- print("Start of indexation")
- print("Indexation can last some time")
- #loading all the pictures in a list
- imagelist = []
- for dirpath, subdirs, files in os.walk(path):
- for x in files:
- try : image = Image.open(os.path.join(dirpath, x))
- except : pass
- photo = ImageTk.PhotoImage(image)
- imagelist.append(photo)
- print(str(len(imagelist)) + " pictures loaded")
- if len(imagelist) == 0:
- raise Exception("no pictures to show in this directory")
- #this label will be used to show pictures
- lbl = Tk.Label(root)
- print("Starting the slideshow")
- def slideshow():
- ok = False
- while ok == False:
- random.seed()
- try:
- #choosing a random picture
- lbl.config(image = imagelist[random.randint(0, len(imagelist)-1)])
- ok = True
- except:
- pass
- random.seed()
- root.after(random.randint(500, 2500), slideshow) #recalling the function after some time
- lbl.pack()
- root.after(100, slideshow)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement