I'm currently building a little GUI using PyQt5 and some html/js scripts that have already been built by someone else for a previous project, and wondering if anyone might be able to help me.
I'm comfortable working in python, but my limited knowledge of html, js and jquery are really making this confusing.
I'm in a situation where I need to be able to take information recorded by the javascript/html and pass it back through to my python script so that I can use it to create a variable for output later on.
I've created a reproducible version below. Currently I'm able to know that gender is being assigned a value when I click, using the buttons. But is there a way that I can pass the value of gender back through to the python script so that I am able to use it there too?
I want to be able to have access to it in successive parts of the app sot hat I can create a profile for the user etc.
pyqtwebtest1.html
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#new_butt").click(function(){
$("#para").hide();
var gender=$ (this).attr('value');
window.alert(gender)
});
$("#other_butt").click(function(){
$("#para").show();
var gender=$ (this).attr('value');
window.alert(gender)
});
});
</script>
</head>
<body>
<h1>My First Heading</h1>
<p id="para">My first paragraph.</p>
<button id ="new_butt" for="Gender_1" value=1> Click me please!</button>
<button id ="other_butt" for="Gender_2" value=25> Click me please!</button>
</body>
</html>
pyqtwebtest.py
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5 import QtWebEngineWidgets
from pathlib import Path
import sys
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
#Create Web View
view = QtWebEngineWidgets.QWebEngineView()
html = Path('stack overflow_pass_test/pyqtwebtest1.html').read_text(encoding="utf8")
view.setHtml(html)
self.setCentralWidget(view)
app = QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec()
I'm wanting to bring all of this information from the javascript/html back through to the python app because I'm much more comfortable working in python, and the successive parts of the app I'm building out really don't rely on the javascript elements. It's just this small part I'm trying to solve.