GUI and Desktop Modules

tkinter.filedialog

Provides modal dialogs for selecting existing files, directories or save destinations. Filename helpers return paths, not necessarily open files; handle cancellation before opening a selected path. Choosing a save path does not itself write data. This example mocks the selected filename.

Formal Syntax & Structure

python syntaxpython
import tkinter.filedialog

Return Value

module

Module namespace available through import; import is a statement, not a value-returning expression.

Working Example

Example Snippetpython
from tkinter.filedialog import askopenfilenamefrom unittest.mock import patchwith patch("tkinter.filedialog.Open.show", return_value="notes.txt"):    print(askopenfilename())
Python Reference