Initial commit
This commit is contained in:
20
source/10-graphical-ui/gui/fileselector.py
Normal file
20
source/10-graphical-ui/gui/fileselector.py
Normal file
@ -0,0 +1,20 @@
|
||||
"""
|
||||
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)
|
Reference in New Issue
Block a user