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

相关推荐
HjhIron4 分钟前
手把手教你用 Next.js 14 + Redis 从零搭建一个全栈 Markdown 笔记系统
前端·全栈·next.js
WIN赢21 分钟前
【抽象思想-从复杂中抽离简单、收敛的口子】
java·前端·javascript
martindelophy30 分钟前
Codex Chrome 插件 + Timeline Studio:构建可编辑的 AI 视频剪辑 Agent 工作流
前端·人工智能·chrome
梦醒沉醉42 分钟前
2、HTML入门——HTML元信息
html
whyutianict_vv1 小时前
从 Web 前端到 HarmonyOS ArkTS:一次 AI 鸿蒙全栈智能体开发的迁移实录
前端·人工智能·harmonyos
qziovv2 小时前
前端转flutter——项目架构、初始化
前端·flutter
Ali885202 小时前
Python字符串方法速查表大全
前端·python
前端_刘师兄2 小时前
FAE工程师学习路线-进程
前端
执子念的飞鱼2 小时前
浏览器直接预览 Pages、Numbers、Keynote:iWork 格式真正难在哪
前端·javascript