PYTHON × WEB × NATIVE
用 Web 构建界面,
让 Python 驱动。
Ultralight 2.x 的 Python 绑定。把 HTML、CSS 和 JavaScript 带到原生桌面,用熟悉的 Python 编写应用逻辑。
● ● ●
● ● ●
Python↔JavaScript
ULTRALIGHT / NATIVE DESKTOPHTML / CSS
Python / asyncio
One application
01 / THE TOOLKIT
从一个窗口,到双向连接。
界面、逻辑与数据,在同一个应用中协作。
02 / YOUR FIRST APPLICATION
从这几行开始。
一个窗口,一次跨语言调用。
先注册 Python 函数,将 API 附着到窗口的 View,再加载页面。JavaScript 直接从命名空间调用函数。
窗口循环由 AppCore 驱动;离屏脚本可以选择 ScriptDriver.auto()。
示例在本地 Python 中运行。安装 wheel 即包含引擎与运行资源,无需单独下载 SDK。
hello.pyPYTHON
from ultralight_py import API, Application
with API("app") as api, Application() as app:
@api.register
def hello(name):
return f"你好,{name}!"
window = app.create_window(800, 520, title="Hello, ultralight-py")
api.attach(window.view)
window.view.load_html("""
<style>
body { background: #111315; color: #edb584;
font: 24px system-ui; padding: 48px; }
</style>
<h1 id="hello"></h1>
<script>
document.querySelector('#hello').textContent = app.hello('世界');
</script>
""")
app.run()
03 / THE REFERENCE
找到你需要的接口。
04 / BUILT WITH ULTRALIGHT-PY
看看它们如何组合。
从桥接实验到桌面游戏,查看原生运行效果、实现思路与源码。