[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版

(yzsuai) #1

canvas’s scrollable (full) size is the image size, and the viewable area size is the minimum
of the physical screen size or the size of the image itself. The physical screen size is
available from the maxsize() method of Toplevel windows. The net effect is that selec-
ted images may be scrolled now, too, which comes in handy if they are too big for your
display (a common case for pictures snapped with newer digital cameras).


In addition, PyPhoto binds keyboard and mouse events to implement resizing and zoom
operations. With PIL, this is simple—we save the original PIL image, run its resize
method with the new image size, and redraw the image in the canvas. PyPhoto also
makes use of file open and save dialog objects, to remember the last directory visited.


PIL supports additional operations, which we could add as new events, but resizing is
sufficient for a viewer. PyPhoto does not currently use threads, to avoid becoming
blocked for long-running tasks (opening a large directory the first time, for instance).
Such enhancements are left as suggested exercises.


Figure 11-9. PyPhoto thumbnail window, other directory


720 | Chapter 11: Complete GUI Programs

Free download pdf