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

相关推荐
IT_陈寒10 分钟前
SpringBoot自动配置的坑差点让我加班到天亮
前端·人工智能·后端
xingpanvip11 分钟前
星盘接口开发文档:星相日历接口指南
android·开发语言·前端·css·php·lua
@PHARAOH23 分钟前
WHAT - GitLens supercharged 插件
前端
TT模板43 分钟前
苹果cms整合西瓜播放器XGplayer插件支持跳过片头尾
前端·html5
Wect1 小时前
React 性能优化精讲
前端·react.js·性能优化
追风筝的人er2 小时前
SpringBoot+Vue3 企业考勤如何处理法定假期?节假日方案、调休补班与工作日判断链路拆解
前端·vue.js·后端
无敌的黑星星2 小时前
Java8 CompletableFuture 实战指南
linux·前端·python
雁鸣零落2 小时前
如何在 Chrome 中查看其他浏览器的书签?书签空间订阅与侧边栏只读切换指南
前端·chrome·edge浏览器
hpoenixf3 小时前
一天上线 + 零返工:我如何给复杂前端需求建立“安全感”
前端
广州华水科技3 小时前
单北斗GNSS变形监测系统在水利工程安全保障中的应用与优势分析
前端