picdir = sys.argv[1]
editstyle = TextEditorComponentMinimal
if len(sys.argv) == 3:
try:
editstyle = [TextEditorMain,
TextEditorMainPopup,
TextEditorComponent,
TextEditorComponentMinimal][int(sys.argv[2])]
except: pass
root = Tk()
root.title('PyView 1.2 - plus text notes')
Label(root, text="Slide show subclass").pack()
SlideShowPlus(parent=root, picdir=picdir, editclass=editstyle)
root.mainloop()
The core functionality extended by SlideShowPlus lives in Example 11-7. This was the
initial slideshow implementation; it opens images, displays photos, and cycles through
a slideshow. You can run it by itself, but you won’t get advanced features such as notes
and sliders added by the SlideShowPlus subclass.
Example 11-7. PP4E\Gui\SlideShow\slideShow.py
"""
######################################################################
SlideShow: a simple photo image slideshow in Python/tkinter;
the base feature set coded here can be extended in subclasses;
######################################################################
"""
from tkinter import *
from glob import glob
from tkinter.messagebox import askyesno
from tkinter.filedialog import askopenfilename
import random
Size = (450, 450) # canvas height, width at startup and slideshow start
imageTypes = [('Gif files', '.gif'), # for file open dialog
('Ppm files', '.ppm'), # plus jpg with a Tk patch,
('Pgm files', '.pgm'), # plus bitmaps with BitmapImage
('All files', '*')]
class SlideShow(Frame):
def init(self, parent=None, picdir='.', msecs=3000, size=Size, args):
Frame.init(self, parent, args)
self.size = size
self.makeWidgets()
self.pack(expand=YES, fill=BOTH)
self.opens = picdir
files = []
for label, ext in imageTypes[:-1]:
files = files + glob('%s/*%s' % (picdir, ext))
self.images = [(x, PhotoImage(file=x)) for x in files]
self.msecs = msecs
PyView: An Image and Notes Slideshow | 735