python-eel / Eel

A little Python library for making simple Electron-like HTML/JS GUI apps
MIT License
6.44k stars 587 forks source link

[BUG] eel call statements in front-end does not work #446

Closed miladsade96 closed 3 years ago

miladsade96 commented 3 years ago

Hi there, We used eel package to connect python back-end with javascript front-end in our project.

We used eel.expose decorator in python file to call python functions in JS side. We have some buttons in index.html so that whenever we click on any button , the corresponding python function should run. But none of them does not work.

For example:

@eel.expose
def image_loader(path="../train_images") -> None:
    """
    Loading images from given directory.
    :param path: str, address of images directory
                default value: train_images directory
    :return: None
    """
    global images_list, cl_names
    # Adding list of contents to a list
    list_of_contents = os.listdir(path)
    for cl in list_of_contents:
        current_image = cv2.imread(f"{path}/{cl}")
        images_list.append(current_image)
        # dropping the file extension
        cl_names.append(os.path.splitext(cl)[0])
 <body>
    <section class="header">
      <div class="container flex">
        <div class="flex-1">
          <h4 class="logo">ASFR</h4>
        </div>
        <small id="date" class="date small"></small>
      </div>
    </section>
    <section class="form gap">
      <div class="input">
        <label for="progress"
          >Progress:
          <progress id="encodeProgress" max="100"></progress>
        </label>
        <button id="load">Load</button>
        <button id="encode">Encode</button>
        <button id="save" class="small">Save</button>
      </div>
    </section>

and the javascript codes:

// will fire if `load` button's click action triggered
loadButton.addEventListener("click", function () {
  // runs eel's image_loader function
  eel.image_loader();
});

OS: Linux, Manjaro KDE Python vesion: 3.9 Browser: Chromium

rahmatagungj commented 3 years ago

What value will be obtained from the image_loader function? try this.

HTML:

<button id="load" onclick="get_image()">Load</button>

Javascript:

function get_image(){
     // runs eel's image_loader function
     eel.image_loader();
}
miladsade96 commented 3 years ago

@rahmatagungj The problem is solved! Thank you