Skip to main content

An Electron-like library for Python using pywebview

Project description

Banner: pytron.png

Pytron

Pytron

This guide provides a step-by-step walkthrough for building desktop applications using the Pytron framework. Pytron combines the power of Python's backend capabilities with the rich user interface of modern web frameworks like React.

Prerequisites

  • Python 3.7+
  • Node.js & npm (for frontend development)

Step 1: Project Setup

  1. Clone/Create Project: Start with the Pytron project structure.
  2. Install Python Dependencies:
    pip install pytron-kit
    

Step 2: Frontend Setup (React + Vite)

We recommend using Vite for a fast and modern development experience.

  1. Initialize App: Navigate to your examples or project folder and run:

    pytron init my_app
    cd my_app/frontend
    
  2. Install Pytron Client: Install the bridge library to communicate with Python.

    npm install pytron-client
    

Step 3: Backend Setup (Python)

  1. Define and Expose Logic: Create functions you want to call from JavaScript and expose them.
        def greet(name):
            return f"Hello, {name}! From Python."
            
        # Expose the function to the frontend
        window.expose(greet)
        
        app.run(debug=True)
    
    if __name__ == '__main__':
        main()
    

Step 4: Connecting Frontend & Backend

Now, use the exposed Python functions in your React components.

  1. Import Client:

    import pytron from 'pytron-client'
    
  2. Call Python Functions: Pytron functions are asynchronous.

    async function handleGreet() {
      try {
        const message = await pytron.greet("User");
        console.log(message); // "Hello, User! From Python."
      } catch (err) {
        console.error("Error calling backend:", err);
      }
    }
    

Step 5: Advanced UI (Frameless Window)

For a native app feel, use a frameless window and create a custom title bar.

  1. Backend: Set frameless=True in create_window.
  2. Frontend: Create a TitleBar component.
    function TitleBar() {
      return (
        <div className="titlebar">
          <div className="drag-region">My App</div>
          <button onClick={() => pytron.minimize()}>-</button>
          <button onClick={() => pytron.close()}>x</button>
        </div>
      )
    }
    
  3. CSS:
    .titlebar {
      display: flex;
      justify-content: space-between;
      background: #333;
      color: white;
      padding: 5px;
      user-select: none;
    }
    .drag-region {
      flex: 1;
      /* This is handled by Pytron's easy_drag or custom implementation */
    }
    

Step 6: Running the App

Run Python Script: bash cd .. pytron run --dev

Step 7: Packaging (Optional)

To distribute your app as a standalone .exe:

pytron package

Happy Coding with Pytron!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytron_kit-0.1.5.tar.gz (1.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytron_kit-0.1.5-py3-none-any.whl (1.7 MB view details)

Uploaded Python 3

File details

Details for the file pytron_kit-0.1.5.tar.gz.

File metadata

  • Download URL: pytron_kit-0.1.5.tar.gz
  • Upload date:
  • Size: 1.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pytron_kit-0.1.5.tar.gz
Algorithm Hash digest
SHA256 ee01e7e3d1a65309dce692aa4eb38147af7fb9acf48e230448b707d1f9010e34
MD5 0ac6386e79eaf48360b1c8a502a30d43
BLAKE2b-256 13fb82740395aaa6a69b4383bc28b4d7d9c17aa6410e96d40aa3c7873a251ab7

See more details on using hashes here.

File details

Details for the file pytron_kit-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: pytron_kit-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pytron_kit-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 86ebaa5f7f650b3b4bc2c97e2a3e51e775bf7c6f0a5766ba8709c4488de3ef33
MD5 1ee1ae29dee0158cac0d184bc429c35c
BLAKE2b-256 372cf2bc3c33c46c290fd4bd1627e0a63328c98d857308106b355c8b3c10372d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page