Hi, as the title says, how can I use the filepicker flet widget and its get_directory_path to extract said directory path ? The documentation just says nothing, and as a beginner I just don’t understand how on earth I can do that. I just know that the option is here !
In this code I’d like the “Sélectionner un répertoire” button to call the filepicker. Then I would be able to go to a directory, select it, and store its path somewhere in the app, like in a variable or plain text or somewhere else. As a bonus, I’d like the selected path to appear below the button.
PS : I know it sounds like I’m just asking you to code for me, but trust me I’ve spent hours trying to do it by myself and I just don’t understand how it works !
Here is the code :
import flet as ft
from flet_route import Params, Basket
from flet import (Page, FilePicker, Text,
ElevatedButton, Row, Column, FilePickerResultEvent)
import subprocess
def parameters(page: ft.Page, params: Params, basket: Basket):
return ft.View(
"/parameters/",
bgcolor='#FFFFFF',
controls=[
ft.Row(
controls=[
ft.IconButton(
icon=ft.icons.ARROW_BACK,
icon_size=20,
on_click=lambda _: page.go("/")
)
],
alignment=ft.MainAxisAlignment.START
),
ft.Container( # Conteneur qui centre la colonne
#bgcolor=ft.Colors.YELLOW, UTILE POUR VOIR LA ZONE DU CONTENEUR
content=ft.Column(
controls=[
ft.ElevatedButton(
"Sélectionner un répertoire",
on_click=lambda _: select_folder
),
],
alignment=ft.MainAxisAlignment.CENTER,
horizontal_alignment=ft.CrossAxisAlignment.CENTER
),
alignment=ft.alignment.center, # Centre tout le contenu
expand=True # Fait en sorte que le container prenne tout l'espace
)
],
vertical_alignment=ft.MainAxisAlignment.CENTER # Centre tout le contenu verticalement
)
Thanks !