简体   繁体   English

使用 python 鳗鱼在 localhost 上的 HTML 中获取目录路径?

[英]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.我正在创建一个 GUI 应用程序,它需要用户选择的文件夹路径。 I am using eel library of python to achieve the GUI with HTML, CSS and JS.我正在使用 python 的 eel 库来实现带有 HTML、CSS 和 JS 的 GUI。 I just want the path to the folder, I don't want the files in that folder to be uploaded.我只想要文件夹的路径,我不希望上传该文件夹中的文件。

Any Solutions?任何解决方案?

So I found a work around with tkinter and may help others.所以我找到了一个解决 tkinter 的方法,并且可以帮助其他人。

in my python I expose a tkinter function to open directories and choose a folder在我的 python 中,我公开了一个 tkinter function 打开目录并选择一个文件夹

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在我的 HTML

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

in my JS I am just calling selectFolder() function from python.在我的 JS 中,我只是从 python 调用 selectFolder() function。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM