How to start another window using eel python?

3.9k Views Asked by At

I am creating a GUI application using eel library in python. index.html contains login form and if login is successful I want to open retrieve.html.

This is my python code and please consider login as successful.

@eel.expose
def retrieve():
    eel.start('retrieve.html', size=(1000, 700))


eel.start('index.html', size=(1000, 700))

This is my javascript code

function login_func()
{
    var username = document.getElementById("username").value
    var pword = document.getElementById("pword").value
    eel.login(username, pword)(set_result)
}

function set_result(result)
{
    if(result == "Failed")
    {
        window.alert("Please insert correct username and password")
    }
    else
    {
        window.close()
        eel.retrieve()
    }
}

Everything works fine but I am getting an error message and that is

OSError: [WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted: ('localhost', 8000)

How can I avoid this?

3

There are 3 best solutions below

0
BHAGATH On

Use different port No. for 2nd window, as mentioned below:

@eel.expose def retrieve(): eel.start('retrieve.html', size=(1000, 700), **port = 8080**)

eel.start('index.html', size=(1000, 700), port = 8000)

or Alternatively, check this https://deecode.net/?p=438&lang=en

0
Omer Meshy On

Make sure that the your port is different for each window

0
dstricks On

You shouldn't call eel.start again... that will setup a new local server, websockets, etc. In this case, you can call eel.show which will re-use your existing web instance to show the new window and page.

So change your code to something like:

@eel.expose
def retrieve():
    eel.show('retrieve.html', size=(1000, 700))