Search code examples
javascriptpythonhtmllocalhosteel

Get directory path in HTML on localhost with python eel?


I am creating a GUI application that requires the path to folder that user selects. I am using eel library of python to achieve the GUI with HTML, CSS and JS. I just want the path to the folder, I don't want the files in that folder to be uploaded.

Any Solutions ?


Solution

  • So I found a work around with tkinter and may help others.

    in my python I expose a tkinter function to open directories and choose a folder

    import tkinter 
    import tkinter.filedialog as filedialog
    
    @eel.expose
    def selectFolder():
        print("Here")
        root = tkinter.Tk()
        root.attributes("-topmost", True)
        root.withdraw()
        directory_path = filedialog.askdirectory()
        print(directory_path)
    

    in my HTML

    <button class="items" onclick="select()">Choose folder</button>
    

    in my JS I am just calling selectFolder() function from python.

    function select(){
      eel.selectFolder();
    }