Create modern cross-platform apps in Python using HTML and CSS
Project description
Neutron allows developers to build native Python apps along with CSS and HTML for frontend design. Based on pywebview for it's native GUI window and JavaScript-Python communication.
You can get started contributing via CONTRIBUTING.md or you can message me on discord (IanTheThird#9732) if you want more insigths on the code and tips on what to contribute.
Installation
pip install neutron-web
Building your project
Note: If you are on linux use ":" instead of ";" in the build command
To build a Neutron project you first need pyinstaller, install pyinstaller throught pip: pip install pyinstaller
. Then run the script below in your command prompt/terminal.
pyinstaller YOUR_PYTHON_FILE.py --noconsole --onefile --add-data="YOUR_HTML_FILE.html;." --add-data="YOUR_CSS_FILE.css;."
Examples
Full example
For a fully set up example project see TEMPLATE. The project is build how it's intended, meaning it has a CSS and HTML file for the design and a Python file for the logic. (It is comparable to how websites using JavaScript are built).
Other examples
Althought not recommended for big projects, it's possible to create an app using only a Python file.
import Neutron
win = Neutron.Window("Example", css="def.css")
HeaderObject = Neutron.elements.Header(win, id="title", content="Hello")
def setName():
HeaderObject.setAttribute("style", "color: red;")
HeaderObject.innerHTML = "Hello world!"
win.getElementById("submit").innerHTML = "clicked!"
Neutron.elements.Button(win, id="submit", content="Hi", onclick=Neutron.event(setName))
win.show()
Another example featuring in-python HTML:
import Neutron
win = Neutron.Window("Example")
def setName():
name = win.getElementById("inputName").value
win.getElementById("title").innerHTML = "Hello: " + name
win.display(f"""
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
</head>
<body>
<h1 id="title">Hello: </h1>
<input id="inputName">
<button id="submitName" onclick="setName()">Submit</button>
</body>
</html>
""", pyfunctions=[setName]) # Link up any Python functions so that they can be used inside the HTML
win.show()
To resolve slow loading times for bigger projects, Neutron features a loader system seen here:
import Neutron
win = Neutron.Window("Example", size=(600,100))
# The loader covers while all the other elements and css loads
win.loader(content="<h1>Loading App...</h1>", color="#fff", after=lambda: win.toggle_fullscreen())
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
Hashes for neutron_web-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9415b1ee5058bad30b36cc822a40498552f924f8ba4412c3f50dcb7811ee10b9 |
|
MD5 | 85ebfed22cf55f8889dc3e45600e8dff |
|
BLAKE2b-256 | f90498c2ab99767185b394ffa43396eec3f83f0ba867302e44f2b3a7723534e4 |