-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslideshow-2.py
More file actions
50 lines (48 loc) · 1.61 KB
/
slideshow-2.py
File metadata and controls
50 lines (48 loc) · 1.61 KB
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
import glob
import os
from itertools import cycle
try:
# Python2
import Tkinter as tk
except ImportError:
# Python3
import tkinter as tk
class App(tk.Tk):
'''Tk window/label adjusts to size of image'''
def __init__(self, image_files, x, y, delay):
# the root will be self
tk.Tk.__init__(self)
# set x, y position only
self.geometry('+{}+{}'.format(x, y))
self.delay = delay
# allows repeat cycling through the pictures
# store as (img_object, img_name) tuple
self.pictures = cycle((tk.PhotoImage(file=image), image)
for image in image_files)
self.picture_display = tk.Label(self)
self.picture_display.pack()
def show_slides(self):
'''cycle through the images and show them'''
# next works with Python26 or higher
img_object, img_name = next(self.pictures)
self.picture_display.config(image=img_object)
# shows the image filename, but could be expanded
# to show an associated description of the image
self.title(img_name)
self.after(self.delay, self.show_slides)
def run(self):
self.mainloop()
# set milliseconds time between slides
delay = 3500
# get a series of gif images you have in the working folder
# or use full path, or set directory to where the images are
image_files = []
os.chdir("./")
for file in glob.glob("*.bin"):
image_files.append(file)
# upper left corner coordinates of app window
x = 100
y = 50
app = App(image_files, x, y, delay)
app.show_slides()
app.run()