link.pack(side=LEFT, expand=YES)
canvas.create_window(colpos, rowpos, anchor=NW,
window=link, width=linksize, height=linksize)
colpos += linksize
savephotos.append(photo)
rowpos += linksize
win.bind('
win.savephotos = savephotos
return win
if name == 'main':
"""
open dir = default or cmdline arg
else show simple window to select
"""
imgdir = 'images'
if len(sys.argv) > 1: imgdir = sys.argv[1]
if os.path.exists(imgdir):
mainwin = viewThumbs(imgdir, kind=Tk)
else:
mainwin = Tk()
mainwin.title(appname + 'Open')
handler = lambda: onDirectoryOpen(None)
Button(mainwin, text='Open Image Directory', command=handler).pack()
mainwin.mainloop()
PyView: An Image and Notes Slideshow
A picture may be worth a thousand words, but it takes considerably fewer to display
one with Python. The next program, PyView, implements a simple photo slideshow
program in portable Python/tkinter code. It doesn’t have any image-processing abilities
such as PyPhoto’s resizing, but it does provide different tools, such as image note files,
and it can be run without the optional PIL extension.
Running PyView
PyView pulls together many of the topics we studied in Chapter 9: it uses after events
to sequence a slideshow, displays image objects in an automatically sized canvas, and
so on. Its main window displays a photo on a canvas; users can either open and view
a photo directly or start a slideshow mode that picks and displays a random photo from
a directory at regular intervals specified with a scale widget.
By default, PyView slideshows show images in the book’s image file directory (though
the Open button allows you to load images in arbitrary directories). To view other sets
of photos, either pass a directory name in as a first command-line argument or change
the default directory name in the script itself. I can’t show you a slideshow in action
here, but I can show you the main window in general. Figure 11-12 shows the main
PyView: An Image and Notes Slideshow | 727