0

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:

  • dialog from HTML/JS, but browser provides just dialog for file/s selection.
  • local dialogs from other libraries, but they are really ugly and not using the default one, for example:

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.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
Foreen
  • 369
  • 2
  • 17
  • What OS are you using Linux/Windows/MacOS? – TheLizzard Sep 08 '22 at 13:45
  • Preferably I want trigger default from all of them (Linux - at least Ubuntu). But if it is not possible, then at least Windows and Linux. But screenshots are from Ubuntu – Foreen Sep 09 '22 at 16:15

1 Answers1

1

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.

TheLizzard
  • 7,248
  • 2
  • 11
  • 31
  • Oh my god! You are amazing! Where can I find this sort of information/packages? Huge thanks to you! – Foreen Sep 09 '22 at 16:18
  • @Foreen This isn't going to be in any online course. I think these things are more about experience. So if you get stuck on something like this, post another question and someone might show you another technique. – TheLizzard Sep 09 '22 at 16:29