另辟蹊径:python利用pywebview用HTML技术实现GUI

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



    
    Title


click me to call python function!

你可能感兴趣的:(另辟蹊径:python利用pywebview用HTML技术实现GUI)