|
há 4 anos atrás | |
---|---|---|
.github | há 4 anos atrás | |
.vscode | há 4 anos atrás | |
nicegui | há 4 anos atrás | |
sceenshots | há 4 anos atrás | |
.gitignore | há 4 anos atrás | |
Dockerfile | há 4 anos atrás | |
LICENSE | há 4 anos atrás | |
README.md | há 4 anos atrás | |
docker-compose.yml | há 4 anos atrás | |
docker.sh | há 4 anos atrás | |
main.py | há 4 anos atrás | |
nicegui.code-workspace | há 4 anos atrás | |
poetry.lock | há 4 anos atrás | |
pyproject.toml | há 4 anos atrás | |
setup.py | há 4 anos atrás |
We like Streamlit but find it does to much magic when it comes to state handling. In search for an alernative nice library to write simple graphical user interfaces in Python we discovered justpy. While too "low-level-html" for our daily usage it provides a great basis for our shot at a "NiceGUI".
python3 -m pip install nicegui
Write your nice GUI in a file main.py
:
from nicegui import ui
ui.label('Hello NiceGUI!')
ui.button('BUTTON', on_click=lambda: print('button was pressed'))
Launch it with:
python3 main.py
Note: The script will automatically reload the GUI if you modify your code.
See main.py for an extensive example what you can do with NiceGUI.
We use the Quasar Framework and hence have their full design power. Each NiceGUI element provides a design
property which content is passed as props the Quasar component:
ui.radio(['x', 'y', 'z'], design='inline color=green')
ui.button(icon='touch_app', design='outline round')
Have a look at the Quasar documentation for all styling "props".
To render a simple plot you create a new context and call the neccessary Matplotlib functions:
with ui.plot():
x = np.linspace(0.0, 5.0)
y = np.cos(2 * np.pi * x) * np.exp(-x)
plt.plot(x, y, '-')
plt.xlabel('time (s)')
plt.ylabel('Damped oscillation')
To update a plot in regular intervals, have look at main.py.
To simplify live updating line plots even more, NiceGUI provides ui.line_plot
with useful parameters and a push
method:
lines = ui.line_plot(n=2, limit=20).with_legend(['sin', 'cos'], loc='upper center', ncol=2)
ui.timer(0.1, lambda: lines.push([datetime.now()], [
[np.sin(datetime.now().timestamp()) + 0.02 * np.random.randn()],
[np.cos(datetime.now().timestamp()) + 0.02 * np.random.randn()],
]))