Skip to content
Advertisement

update elements in electron with python (and flask?)

I am trying to use a python script to update elements on electron. I have read many tutorials but most of them didn’t work and the one that did work I couldn’t understand how to change it to use it in my program. For this reason I have created an electron app that updates a <p> element with javascript and another <p> element that should be updated by python. From what I have read I need to use flask which I don’t know and that’s why I need someone to explain to me how to call the python functions with javascript and what flask code I need in the .py file. Here are the files of my project:

main.js (the one generated automatically by electron forge normally named index.js just renamed)

JavaScript

index.html (the html file of the page that will be updated with python)

JavaScript

index.js (the .js file of the page that will be updated with python)

JavaScript

hello.py (the python file whose hello() function I would like to call)

JavaScript

Also should the python function always return a string or can it return more complex things like a list or a dataframe and use each value in a different html element? Thank you for your time

Advertisement

Answer

You can use JQuery to make a GET request to a Flask route.

JS:

JavaScript

Python:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement