pip install pywebview
程序运行
终端输出
完整python代码如下.
import webview
html = """
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
</head>
<body>
<h1 id='adw'>在python里运行js </h1>
</body>
</html>
"""
def evaluate_js(mm): #使用window.evaluate_js函数在python中任意调用js
result = window.evaluate_js(
"""
var dd = document.getElementById('adw');
y = dd.innerText
"""
)
print(result)
if __name__ == '__main__':
window = webview.create_window('Run custom JavaScript',html=html)
webview.start(evaluate_js,window)