We're back after a server migration that caused effbot.org to fall over a bit harder than expected. Expect some glitches.

File Dialogs

The tkFileDialog module can be used to get a filename from the user. The module provides two convenience functions, one to get an existing filename so you can open it, and one to get a new filename, to save things into.

tkFileDialog.askopenfilename([options]). If the dialog is cancelled by the user, the function returns None.

tkFileDialog.asksaveasfilename([options]).

Figure 9-6. askopenfilename, asksaveasfilename

The following options can be used with the askopenfilename and asksavefilename functions:

Table 9-4. askopenfilename options

Option

Type

Description

defaultextension

string

An extension to add to the filename, if not explicitly given by the user. The string should include the leading dot (ignored by the open dialog).

filetypes

list

Sequence of (label, pattern) tuples. The same label may occur with several patterns. Use “*” as the pattern to indicate all files.

initialdir

string

Initial directory.

initialfile

string

Initial file (ignored by the open dialog)

parent

widget

Which window to place the message box on top of. When the dialog is closed, the focus is returned to the parent window.

title

string

Message box title.