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
- Clone/Create Project: Start with the Pytron project structure.
- Install Python Dependencies:
pip install pytron-kit
Step 2: Frontend Setup (React + Vite)
We recommend using Vite for a fast and modern development experience.
-
Initialize App: Navigate to your examples or project folder and run:
pytron init my_app cd my_app/frontend
-
Install Pytron Client: Install the bridge library to communicate with Python.
npm install pytron-client
Step 3: Backend Setup (Python)
- 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.
-
Import Client:
import pytron from 'pytron-client'
-
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.
- Backend: Set
frameless=Trueincreate_window. - 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> ) }
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytron_kit-0.1.0.tar.gz.
File metadata
- Download URL: pytron_kit-0.1.0.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6be44cfd225155ffd62275faf3928fa198e91703d5284231c33824babd603239
|
|
| MD5 |
dfa4ec8fc2e868769f8e21aaebaa4208
|
|
| BLAKE2b-256 |
3f2c9ecece26f0f7fb794c876c16692735fab3c549ed949e570cd190d4c167bb
|
File details
Details for the file pytron_kit-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pytron_kit-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52f8e913d4bd0876f4c7ecb90268f421629ec3e5e29a4cdab72810b3e4b69a34
|
|
| MD5 |
03a74bb4aa0fc1b745fda6fcbe1f98e0
|
|
| BLAKE2b-256 |
971864b2a2ef7dac53ca09828066b38f64e7c3209c3628c67f938a4114457372
|