python-eel / Eel

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

redirecting pages while keep python running #667

Open privacyrespected opened 1 year ago

privacyrespected commented 1 year ago

Similar to #426 , I am trying to redirect pages while keeping python running So i have just ran a loading screen on python and i am trying to switch from index.html to home.html once python is done loading. I have tried the solution on #426 too

import eel
import time
eel.init('web')

@eel.expose
def load_modules():
    import pandas as pd
    from sklearn.linear_model import LinearRegression
    from sklearn.model_selection import train_test_split
    import yfinance as yf
    from datetime import datetime, timedelta
    print('load done')
    done = "1"
    eel.go_to('home.html')
    return done

eel.start('index.html')
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>OMEGA</title>
    <script type="text/javascript" src="/eel.js"></script>
    <script type="text/javascript" src="main.js"></script>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body onload="load_modules()">
    <div class="omega">OMEGA</div>
    <div class="loading">
        <div class="spinner"></div>
        <div class="loading-text">Loading...</div>
    </div>
</body>
</html>
eel.expose(go_to)
function go_to(url) {window.location.replace(url);};
function callback(done){
    if (done === done) {
        //window.location.href = "home.html";
        //go_to('home.html')
    }      
}

function load_modules(){
    eel.load_modules()(callback)
};

so once its done loading, it should be redirected to another page called

home.html

Problem is: Once everything is done and index.html is redirected to home.html, my python code stops. I think I know why..? (probably because index.html is closed to the program stops) is there a way to keep the python code running despite changing to another page?

Many thanks

selltool commented 11 months ago

Helpppp

FabricioSerrano commented 2 months ago

Apparently, all your html files need to have this link to eel modules, using this should keep app running after changing the url.

Like this: <script type="text/javascript" src="/eel.js"></script>