21 lines
895 B
Python
21 lines
895 B
Python
"""
|
|
Example code to select file using a file dialog.
|
|
|
|
Needs a Qt Application object and then a File dialog object.
|
|
The `getOpenFileName()` method on the file dialog object opens
|
|
a dialog for loading a single file. It returns a tuple, containing
|
|
the selected file name (str) and the filter (str).
|
|
If no file was selected (cancelled), you get empty strings in the tuple.
|
|
"""
|
|
from PySide6.QtWidgets import QFileDialog, QApplication
|
|
|
|
application = QApplication()
|
|
# You don't need application.exec() here because the method blocks the python script execution.
|
|
dialog = QFileDialog(directory="/home/steve", caption="Sélectionnez un fichier", filter="Text files (*.txt);; All files (*.*)")
|
|
selection: tuple[str, str] = dialog.getOpenFileName()
|
|
print(selection)
|
|
|
|
with open("/home/steve/Code/training/python/beginner/documentation/12-logging.md", "r") as file:
|
|
lines = file.readlines()
|
|
print(lines)
|