Skip to main content

An Electron-like library for Python using pywebview

Project description

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.3.tar.gz (1.6 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.3-py3-none-any.whl (1.6 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytron_kit-0.1.3.tar.gz
  • Upload date:
  • Size: 1.6 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.3.tar.gz
Algorithm Hash digest
SHA256 8ad4382d3422622b2de6372e61701f5be33cacdd64faec94ef11f5a92af20f33
MD5 f383eea62ae8e429151c9b062aa63d18
BLAKE2b-256 6d33607c3066bef61058540c177fb73487e98418a05a3a5661aa320748ead480

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytron_kit-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 1.6 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f92e02cf6c06fe69d9e611535fa28f28e6090a3a5f309841a71dc34be4aad69a
MD5 8b2275e077907e1e06e00287f2a7721a
BLAKE2b-256 a6a396adbf1b97f90ee1732a3a7cd6bff9dac9955ea6fcad7286ca989ccfa635

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