tag because of security reasons. So please tell me a way to get t" /> tag because of security reasons. So please tell me a way to get t" /> tag because of security reasons. So please tell me a way to get t"/>

How to take image input from user in eel python?

998 Views Asked by At

I am using eel library to create GUI. I can't get the path using <input type="file"> tag because of security reasons. So please tell me a way to get the image and display it in eel interface. I show several questions related to this but I didn't find any full answer.

<body>
    <button type="button" onclick="getPathToFile()">Select File</button>
    <img id="myImg" src="" width="107" height="98">
</body>
1

There are 1 best solutions below

0
rafalou38 On

solution:

You have to use tkinter's file dialog to get files

Explanation:

Browsers include a lot of security measures to protect user's data. Since you are on a local server (eel) there are some things you may have to do with python like getting files on the system.

example:

# ==> PYTHON

from tkinter import filedialog, Tk, messagebox
import os

@eel.expose
def getFile ():
    root = Tk()
    root.withdraw()
    root.wm_attributes('-topmost', 1) # without that it wil go behind all others apps
    file = filedialog.askopenfilename(parent=root,
     initialdir=os.getcwd(),
     title = "Ouvrez un fichier pickle",
     filetypes = (
       ("images","*.png"),
       ("all files","*.*")
     )
    )
    return file

to call it:

// ==> JAVASCRIPT

async function example(){
    let file = await eel.getFile()()
}

Go further:

  1. For more info: filedialog docs
  2. How an app made with eel (auto-py-to-exe) did it: GitHub