pywebview
官网:https://pywebview.flowrl.com/
Build GUI for your Python program with JavaScript, HTML, and CSS
最简单的实例
实现了python与html的双向交互
- python文件
import webview
import random
def test():
return random.randint(1, 1000)
def expose(window):
window.evaluate_js('alert("hello from python!")') # python里执行js
if __name__ == '__main__':
win = webview.create_window('JS Expose Example', 'index.html', text_select=True)
win.expose(test) # 允许html页面里访问test
webview.start(expose, win) # 启动webview时调用expose
- HTML文件:index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1 onclick="pywebview.api.test().then(function(res){alert(res)})">click me to call python function!</h1>
</body>
</html>