File Dialog
Overview
This document explains how to open a file dialog and select files or directories. This functionality is implemented using PySide's QFileDialog
class. This document covers three methods: open_file_dialog
, save_file_dialog
, and select_directory_dialog
.
Method Descriptions
open_file_dialog
open_file_dialog
Opens a dialog to open a file.
Parameters
dir
(str, optional): The directory where the dialog will initially open. Default is the current working directory.filter
(str, optional): A string specifying the selectable file types. For example, it can be used like"Text Files (*.txt);;All Files (*)"
.
Return Value
Optional[str]
: Returns the path of the selected file. ReturnsNone
if no file is selected.
Example
save_file_dialog
save_file_dialog
Opens a dialog to save a file.
Parameters
dir
(str, optional): The directory where the dialog will initially open. Default is the current working directory.filter
(str, optional): A string specifying the savable file types. For example, it can be used like"Text Files (*.txt);;All Files (*)"
.
Return Value
Optional[str]
: Returns the path of the selected file. ReturnsNone
if no file is selected.
Example
select_directory_dialog
select_directory_dialog
Opens a dialog to select a directory.
Parameters
dir
(str, optional): The directory where the dialog will initially open. Default is the current working directory.
Return Value
Optional[str]
: Returns the path of the selected directory. ReturnsNone
if no directory is selected.
Example
Note
These methods are implemented using PySide6's QFileDialog
class. PyQt is a binding that allows the use of the Qt library in Python. QFileDialog
provides standard dialogs for selecting files and directories.
Last updated