Basic
Un conjunto de herramientas GUI nativo de Python y del sistema operativo.
Introducció
Toga iss available on macOS, Windows, Linux (GTK), Android, iOS, for single-page web apps, and console apps.
Toga uses native system widgets, not themes. When you see a Toga app running, it doesn’t just look like a native app - it is a native app. Applying an operating system-inspired theme over the top of a generic widget set is an easy way for a developer to achieve a cross-platform goal, but it leaves the end user with the mess.
Native widgets are always faster than a themed generic widget. After all, you’re using native system capability that has been tuned and optimized, not a drawing engine that’s been layered on top of a generic widget. They also inherit all of the native platform’s accessibility affordances, such as support for screen readers and adaptive font sizes.
Toga has been designed from the ground up to be a Python native widget toolkit. This means the API is able to exploit language level features like generators and context managers
Your first Toga app
Crea un projecte toga-basic amb uv:
uv init toga-basic
cd toga-basic
uv add togaWrite the app
Modifica el fitxer main.py:
=
=
= 50
= 1
return
=
Let’s walk through this one line at a time.
The code starts with imports. First, we import toga:
Then we set up a handler, which is a wrapper around behavior that we want to activate when the button is pressed. A handler is just a function. The function takes the widget that was activated as the first argument; depending on the type of event that is being handled, other arguments may also be provided. In the case of a simple button press, however, there are no extra arguments:
Estás leyendo una vista previa.
Inicia sesión para leer el artículo completo. Cualquier cuenta abre 4 artículos gratuitos al mes; el alumnado y el profesorado leen las páginas de su curso sin límite.
Iniciar sesión