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

media/cache/8df285a845f85ba0944b5535943fa6a7.gif

media/cache/8b18494a76c1b1732af9c5d63b5ac729.gif

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.

 

A Django site. rendered by a django application. hosted by webfaction.