Pywebview

6.2 · active · verified Mon Apr 13

Pywebview is a lightweight cross-platform wrapper for webview components, allowing you to build desktop GUI applications with HTML, CSS, and JavaScript. It abstracts away platform-specific webview implementations (Edge Chromium, Cocoa WebKit, GTK, QT, WinForms, etc.) providing a consistent Python API. The current version is 6.2 and it follows an active release cadence with frequent updates and bug fixes.

Warnings

Install

Imports

Quickstart

This quickstart creates a simple pywebview window, loads HTML content, exposes a Python function to JavaScript, and calls it from the browser context to update a paragraph on the page.

import webview

def hello_world(window):
    """Function to be executed after the window is ready."""

    # Expose a Python function to JavaScript
    def get_message():
        return "Hello from Python!"
    window.expose(get_message)

    # Execute JavaScript after the window is fully loaded
    # Access the exposed Python function via window.pywebview.api
    window.evaluate_js(
        "document.getElementById('message').innerText = 'Loading...';"
    )
    window.evaluate_js(
        "window.pywebview.api.get_message().then(result => {"
        "document.getElementById('message').innerText = result;" 
        "});"
    )

html_content = """
<!DOCTYPE html>
<html>
<head>
    <title>Pywebview App</title>
</head>
<body>
    <h1>Pywebview Example</h1>
    <p id="message">Waiting for Python to load...</p>
</body>
</html>
"""

if __name__ == '__main__':
    # Create a webview window
    window = webview.create_window(
        'My First Pywebview App',
        html=html_content,
        width=800, 
        height=600
    )
    
    # Start the webview application. 
    # The 'hello_world' function will be called when the window is ready.
    webview.start(hello_world, window)

view raw JSON →