javascriptpythonuser-interfacepywebview

Python GUI enter data to database


I'm trying to create a gui application for python. I came across many bookstores. tkinter, qt and many others. I find Tkinter effective but very ugly on an aesthetic level. Qt I find great but also very complex.

So I decided to rely on pywebview, and delegate the graphic rendering to the browser with HTML and JS. I find it much faster and more intuitive. however I would like to create a database (sqlite3) and insert/edit/delete the values. The pywebview documentation is quite sparse, so I'm having trouble entering values into a form and sending them to a python function.

My question is how can I bridge between js and python? suppose we want to add a simple name to a database column via a form, I can't figure out how to call the python function in the HTML code.

I know you have to work with Class API() but I can't find any good examples

Any tips on how to make a bridge?


Solution

  • Author here.

    You can find a JS API example here https://pywebview.flowrl.com/examples/js_api.html

    Alternatively you can use window.expose(yourFunc) to expose a Python function to Javascript. It will be available as pywebview.api.yourFunc in Javascript.