I'm attempting to run python script through an html button for my electron app. However, I'm having issues with connecting the python code to the html button.
I'm using visual studio code for JavaScript and python. All the files are saved in the same folder/directory.
Here's my python code (script.py):
import sys
num1 = 3.2
num2 = 4.1
sum = float(num1) + float(num2)
print("The sum of {0} and {1} is {2}" .format(num1, num2, sum))
num3 = 5.3
num4 = 6.9
sum2 = float(num3) * float(num4)
print("The sum of {0} and {1} is {2}" .format(num3, num4, sum2))
sys.stdout.flush()
Here's my HTML code (Wifi.html):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" type="text/css" media="screen" href="main2.css" />
<script src="g/script.js"></script>
</head>
<body>
<h1>A</h1>
<br>
<h2>W</h2>
<ul>
<li><button id="add" class="btn btn-warning" onclick="get_script()">Run Test</button></li>
</ul>
<div class=back>
<input type=button onClick="location.href='DoS.html'" value='BACK'>
</div>
</body>
</html>
Here is the JavaScript file I'm trying to connect python with JavaScript/electron:
function get_script(){
var python = require("python-shell")
var path = require("path")
var options = {
scriptPath : path.join(/g/script.py'),
pythonPath : '/path'
}
var pleasewrk = new python("script.py", options);
pleasewrk.on('message', function(message){
swal(message);
})
}
I would like for python code to be run and appear on either the same or pop-up page.