Javascript 如何通过单击按钮从electron执行Python脚本?
try.html文件:-Javascript 如何通过单击按钮从electron执行Python脚本?,javascript,python,anaconda,electron,Javascript,Python,Anaconda,Electron,try.html文件:- <html> <head> <title>Hello World!</title> </head> <body> <input type="button" class="btn" id="processbtn" value="Process" onclick="get_tt()"/> <script src="try3.js"></script>
<html>
<head>
<title>Hello World!</title>
</head>
<body>
<input type="button" class="btn" id="processbtn" value="Process"
onclick="get_tt()"/>
<script src="try3.js"></script>
</body>
</html>
python代码未使用此代码执行。按钮的值更改为挂起,并保持不变。你好。
hello.py
文件的内容是什么?由于您有一个end
事件的侦听器,因此可能是您的脚本没有正确终止,并且您从未获得end事件。此外,您还可以从python文件登录到一个文件或其他类似文件,以确保调用它。您在控制台上看到任何错误吗?@limoragni hello.py:-import sys print('hello from Python!')sys.stdout.flush()Hi-KU。hello.py
文件的内容是什么?由于您有一个end
事件的侦听器,因此可能是您的脚本没有正确终止,并且您从未获得end事件。此外,您还可以从python文件登录到一个文件或其他类似文件,以确保调用它。您在控制台上看到任何错误吗?@limoragni hello.py:-import sys print('hello from Python!')sys.stdout.flush()
function get_tt() {
document.getElementById("processbtn").value = "Hang on..."
var python=require("python-shell")
var path = require("path")
var options = {
scriptPath : path.join(__dirname,''),
pythonPath : 'C:/Users/Lenovo/Anaconda3/python'
}
var f = new python("hello.py",options);
f.end(function(err, code, message) {
document.getElementById("processbtn").value = "Done";
})
}