python_pywebview示例

import webview

class Api:
    def __init__(self):
        self.window = None
    
    def splash_closed(self):
        print("启动画面关闭,创建带边框主窗口")
        # 关闭当前无边框窗口
        #webview.windows[0].destroy()
        win1=webview.windows[0]
        # 创建带边框主窗口
        main_window = webview.create_window(
            '主窗口',
            html='<h1>欢迎使用</h1>',
            width=1200,
            height=800,
            frameless=False
        )
        self.window=main_window
        webview.windows[0]=main_window
        win1.destroy()

def create_splash():
    html = """
    <!DOCTYPE html>
    <html>
    <style>
        #splash {
            position: fixed; top: 0; left: 0;
            width: 100%; height: 100%;
            background: #2c3e50;
            display: flex;
            justify-content: center;
            align-items: center;
            flex-direction: column;
        }
        .loader {
            border: 5px solid #f3f3f3;
            border-top: 5px solid #3498db;
            border-radius: 50%;
            width: 50px; height: 50px;
            animation: spin 2s linear infinite;
        }
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
    </style>
    <body>
        <div id="splash">
            <div class="loader"></div>
            <p style="color:white;margin-top:20px">加载中...</p>
        </div>
        <script>
            setTimeout(() => {
                pywebview.api.splash_closed();
            }, 3000);
        </script>
    </body>
    </html>
    """

    window = webview.create_window(
        '启动画面',
        html=html,
        width=800,
        height=600,
        frameless=True,
        easy_drag=True
    )
    api = Api()
    window.expose(api.splash_closed)
    webview.start(icon="logo.jpg")

if __name__ == '__main__':
    create_splash()

  

posted @ 2025-07-10 00:05  Pynix  阅读(119)  评论(0)    收藏  举报