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

How to use close_callback? #307

Closed SaranSundaresan closed 4 years ago

SaranSundaresan commented 4 years ago

HI. When I close my existing eel window, the python program still remains executing. Moreover, the localhost instance still remains active. I need to find a way to close the localhost instance and also the python program, if required, at the same time that I close the eel window.

I believe close_callback will help me accomplish the above objective. But I'm getting the syntax wrong and I'm unable to understand the syntax well enough from the doc. Pls help!

std-odoo commented 4 years ago

If you want to close the application when you close the window, here is the syntax :)

import eel

def close_callback(route, websockets):
    if not websockets:
        exit()

eel.init("web")
eel.start("main.html", close_callback=close_callback)

web/main.html

<html>
    <body>
        <script type="text/javascript" src="/eel.js"></script>
        <div>bouh</div>
    </body>
</html>

The function close_callback takes 2 arguments

Hope it helps

samuelhwilliams commented 4 years ago

@SaranSundaresan this really shouldn't be happening if you're running the latest version of Eel. Can you share your code, your Python version, and Eel version?

The close callback that @std-odoo kindly shared should already be the default behaviour: https://github.com/samuelhwilliams/Eel/blob/bb058329b64b2f3e8d3e5d0e8a4cd6f3d3eab3b7/eel/__init__.py#L330-L340

samuelhwilliams commented 4 years ago

I'm going to close this based on inactivity - but please reach out if you're still having issues.