pywebview打包本地的html

51.安装 pip install pywebview

2.新建start.py

python 复制代码
import webview
import time


class API:
    def say_hello(self, name):
        time.sleep(2)  # 模拟一个耗时操作
        return f'Hello, {name}!'


def main():
    api = API()
    webview.create_window('pywebview Example', 'index.html', js_api=api)
    webview.start()


if __name__ == '__main__':
    main()

3.新建index.html

html 复制代码
<!DOCTYPE html>
<html>
<head>
    <title>pywebview Example</title>
</head>
<body>
    <h1>Hello, pywebview!</h1>
    <button onclick="callPython()">Call Python</button>
    <script type="text/javascript">
        function callPython() {
            window.pywebview.api.say_hello('World').then(response => {
                alert(response);
            });
        }
    </script>
</body>
</html>

4.创建一个.spec文件

pyinstaller --name=myapp --onefile start.py

5.打开生成的.spec文件

修改如下图所示:

6.最后,保存.spec文件并运行以下命令来构建你的应用

pyinstaller myapp.spec

相关推荐
家里有只小肥猫6 分钟前
uniApp小程序保存canvas图片
前端·小程序·uni-app
前端大全8 分钟前
Chrome 推出全新的 DOM API,彻底革新 DOM 操作!
前端·chrome
前端小臻35 分钟前
关于css中bfc的理解
前端·css·bfc
Ama_tor42 分钟前
网页制作05-html,css,javascript初认识のhtml表格的创建
javascript·css·html
白嫖不白嫖1 小时前
网页版的俄罗斯方块
前端·javascript·css
HappyAcmen1 小时前
关于Flutter前端面试题及其答案解析
前端·flutter
饼干饿死了1 小时前
实现动态翻转时钟效果的 HTML、CSS 和 JavaScript,附源码
javascript·css·html
白嫖不白嫖1 小时前
小游戏-记忆卡牌
css·html·css3
顾比魁1 小时前
pikachu之CSRF防御:给你的请求加上“网络身份证”
前端·网络·网络安全·csrf
林的快手1 小时前
CSS文本属性
前端·javascript·css·chrome·node.js·css3·html5