安装:
1 | pip install pywebview |
Hello world:
1 2 3 | import webview webview.create_window('Hello world', 'https://pywebview.flowrl.com/hello') webview.start() |
Explore pywebview further by reading documentation, examples or contributing. If React is your thing, get started right away with React boilerplate.
您可以根据需要创建任意多个窗口。GUI 循环启动后创建的 Windows 将立即显示。所有打开的窗口都作为列表存储在
1 2 3 4 | import webview webview.create_window('Woah dude!', html='<h1>Woah dude!<h1>') webview.start() |
请注意,如果同时设置了
HTTP server
1 2 3 4 | import webview webview.create_window('Woah dude!', 'index.html') webview.start(http_server=True) |
如果希望将外部 WSGI 兼容的HTTP服务器与
1 2 3 4 5 6 | from flask import Flask import webview server = Flask(__name__, static_folder='./assets', template_folder='./templates') webview.create_window('Flask example', server) webview.start() |
Threading model
1 2 3 4 5 6 7 8 9 10 | import webview def custom_logic(window): window.toggle_fullscreen() window.evaluate_js('alert("Nice one brother")') window = webview.create_window('Woah dude!', html='<h1>Woah dude!<h1>') webview.start(custom_logic, window) # anything below this line will be executed after program is finished executing pass |
Make Python and Javascript talk with each other
您可以将自定义逻辑视为与 HTML/JS 领域中的 前端代码进行通信的后端。现在,您将如何使二者互相交流?