-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrollingImages.py
61 lines (45 loc) · 1.72 KB
/
scrollingImages.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#On raspberian remove the from PIL and ser the tkinter to Tkinter in all reference locations
import os, tkinter, glob
from PIL import Image, ImageTk, ImageFile
from random import randint
def changeImage():
ImageFile.LOAD_TRUNCATED_IMAGES = True
#open the config file and get the image folder location and the display time
file = open('config.cfg', 'r')
global fileValues
fileValues = file.read().split(',')
file.close()
global tkpi #need global so that the image does not get derefrenced out of function
try:
#get random image\
filename = getfiles()
image = Image.open(filename)
#Resize image for an 800x450 screen
image = image.resize((800,450), Image.NEAREST)
#Creates a Tkinter compatible photo image
tkpi = ImageTk.PhotoImage(image)
#Put image in a label and place it
label_image = tkinter.Label(root, image=tkpi)
label_image.place(x=0,y=0,width=image.size[0],height=image.size[1])
# call this function again in the value set in the config file
root.after(fileValues[1], changeImage)
except ValueError:
print("Error")
#Get the files in the config directory then randomize them and return the single file name
def getfiles():
filePath = fileValues[0]
try:
allfiles = glob.glob(filePath + "/*.jpg")
numfiles = len(allfiles)
arraypos = (randint(0, numfiles-1))
print(arraypos)
return allfiles[arraypos]
except ValueError:
thefile = getfiles();
return thefile
#create this global variable so that the image is not derefrenced
tkpi = None
root = tkinter.Tk()
root.geometry('800x450') # Size Width 800, Heigh 480
changeImage()
root.mainloop()