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

相关推荐
指尖跳动的光7 分钟前
前端视角-如何保证系统稳定性
前端
fruge9 分钟前
2025全栈技术深耕与实践:从框架融合到工程落地
前端
秋42719 分钟前
tomcat与web服务器
服务器·前端·tomcat
hdsoft_huge28 分钟前
Java 实现高效查询海量 geometry 及 Protobuf 序列化与天地图前端分片加载
java·前端·状态模式
MoonBit月兔29 分钟前
用 MoonBit 打造的 Luna UI:日本开发者 mizchi 的 Web Components 实践
前端·数据库·mysql·ui·缓存·wasm·moonbit
程序员修心31 分钟前
CSS浮动与表格布局全解析
前端·html
POLITE31 小时前
Leetcode 238.除了自身以外数组的乘积 JavaScript (Day 7)
前端·javascript·leetcode
光影少年1 小时前
AI前端开发需要会哪些及未来发展?
前端·人工智能·前端框架
Vincent_Vang1 小时前
多态 、抽象类、抽象类和具体类的区别、抽象方法和具体方法的区别 以及 重载和重写的相同和不同之处
java·开发语言·前端·ide
菩提小狗1 小时前
小迪安全_第4天:基础入门-30余种加密编码进制&Web&数据库&系统&代码&参数值|小迪安全笔记|网络安全|
前端·网络·数据库·笔记·安全·web安全