美文网首页
Eel创建桌面程序

Eel创建桌面程序

作者: 风一样的存在 | 来源:发表于2019-03-03 19:54 被阅读0次

    eel是python开发桌面应用程序的一个小框架,本质打开机器上的浏览器运行html/js页面的。
    首先先安装eel

    pip install eel
    

    创先python项目,编写对应的web页面:


    eel.png

    编写启动脚本:

    import eel
    
    # 暴露方法给前端js调用
    @eel.expose
    def sayHello():
        return "this is my first app"
    
    # 指定对应的目录
    eel.init("web")
    # 指定启动的开始页面
    eel.start("index.html")
    

    前端页面:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
        <link rel="stylesheet" href="metro/css/metro-all.min.css">
    </head>
    <body class="bg-blue fg-white">
    <h1 class="text-center">Metro 4</h1>
    <h3 class="text-center">The Components Library</h3>
    <div data-role="cube"></div>
    
    <script src="jquery/jquery-3.3.1.min.js"></script>
    <script src="metro/js/metro.min.js"></script>
    <script src="/eel.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            console.info(eel.sayHello());
        })
    </script>
    </body>
    </html>
    

    运行效果:

    eel.png
    出现找不到eel这个文件的提示,请确定External Libraries是否含有eel.js文件
    image.png

    相关文章

      网友评论

          本文标题:Eel创建桌面程序

          本文链接:https://www.haomeiwen.com/subject/gtpmuqtx.html