pythonwebeelpywebview

Eel - ask for directory input


I am developing modern-looking local app in Python with Eel and I want to open OS's default dialog to select directory. But I have found that Eel does not provide that.

I have tried:

Tkinter (ttk is not that much better):

tkinter

tkfilebrowser:

tkfilbrowser

Anybody knows, how can I open OS's default directory selection via some simple lightweight library/eel? (at least on Linux-Ubuntu and Windows)

default

Or are there any other lightweight alternatives to eel, that would do that? I know about pywebview, but it is slower than eel and it is not that lightweight.


Solution

  • I don't think there is any way to change how the tkinter folder selection dialog looks. But you can use something like this (should work on Linux):

    from subprocess import Popen, PIPE
    from time import sleep
    
    
    COMMAND = "zenity --file-selection --directory"
    
    def ask_folder() -> str:
        # Open a new process with the command
        proc = Popen(COMMAND, shell=True, stdout=PIPE)
        # Wait for the process to exit
        while proc.poll() is None:
            sleep(0.1)
    
        # Read the stdout and return the result
        stdout_text = proc.stdout.read()
        directory = stdout_text.decode().strip("\n")
        if directory == "":
            return None
        else:
            return directory
    
    folder = ask_folder()
    print(f"Selected: \"{folder}\"")
    

    If you change the COMMAND, based on the OS, you should be able to get this to work on all OSes.