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

(yzsuai) #1

  • They can be passed an initialdir (start directory), initialfile (for “File name”),
    title (for the dialog window), defaultextension (appended if the selection has
    none), and parent (to appear as an embedded child instead of a pop-up dialog).

  • They can be made to remember the last directory selected by using exported objects
    instead of these function calls—a hook we’ll make use of in later longer-lived
    examples.


Another common dialog call in the tkinter filedialog module, askdirectory, can be
used to pop up a dialog that allows users to choose a directory rather than a file. It
presents a tree view that users can navigate to pick the desired directory, and it accepts
keyword arguments including initialdir and title. The corresponding Directory ob-
ject remembers the last directory selected and starts there the next time the dialog is
shown.


We’ll use most of these interfaces later in the book, especially for the file dialogs in the
PyEdit example in Chapter 11, but feel free to flip ahead for more details now. The
directory selection dialog will show up in the PyPhoto example in Chapter 11 and the
PyMailGUI example in Chapter 14; again, skip ahead for code and screenshots.


Finally, the demo bar’s Color button triggers a standard askcolor call, which generates
the standard color selection dialog shown in Figure 8-15.


Figure 8-14. demoDlg open, askopenfilename dialog


Dialogs | 433
Free download pdf