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

相关推荐
kungggyoyoyo12 分钟前
TRAE中国版SOLO模式上线!我用它从0到1开发了一款AI小说编辑器
前端·vue.js·trae
ohyeah14 分钟前
栈:那个“先进后出”的小可爱,其实超好用!
前端·数据结构
心随雨下24 分钟前
typescript中Triple-Slash Directives如何使用
前端·javascript·typescript
自在极意功。29 分钟前
AJAX 深度详解:从基础原理到项目实战
前端·ajax·okhttp
s***45330 分钟前
SpringBoot返回文件让前端下载的几种方式
前端·spring boot·后端
海上彼尚35 分钟前
[逆向] 1.本地登录爆破
前端·安全
什么时候吃饭39 分钟前
vue2、vue3父子组件嵌套生命周期执行顺序
前端·vue.js
2501_9409439140 分钟前
体系课\ Python Web全栈工程师
开发语言·前端·python
q***064741 分钟前
SpringSecurity相关jar包的介绍
android·前端·后端
低保和光头哪个先来1 小时前
场景2:Vue Router 中 query 与 params 的区别
前端·javascript·vue.js·前端框架