# BeeWare Toga — Native Cross-Platform GUI Apps in Python > Write native desktop and mobile applications in pure Python that render with platform-native widgets on macOS, Windows, Linux, iOS, Android, and the web. ## Install Save as a script file and run: # BeeWare Toga — Native Cross-Platform GUI Apps in Python ## Quick Use ```bash pip install toga cat > app.py << 'PYEOF' import toga def build(app): box = toga.Box() label = toga.Label("Hello, BeeWare!", style=Pack(padding=20)) box.add(label) return box app = toga.App("Hello", "org.example.hello", startup=build) app.main_loop() PYEOF python app.py ``` ## Introduction Toga is the widget toolkit of the BeeWare project, designed to let Python developers build native graphical applications for desktop and mobile platforms. Rather than drawing its own widgets, Toga maps Python code to each platform's native GUI framework — Cocoa on macOS, GTK on Linux, Winforms on Windows, UIKit on iOS, and Android views — producing apps that look and behave like first-class citizens on every OS. ## What Toga Does - Maps a Pythonic widget API to native platform controls on macOS, Windows, Linux, iOS, and Android - Provides layout via the Pack style engine, a CSS-like flexbox system for positioning widgets - Ships with common widgets: buttons, text inputs, tables, trees, web views, image views, and more - Integrates with Briefcase (the BeeWare packaging tool) for creating distributable app bundles - Supports a web backend that renders the same app in a browser via a server-side model ## Architecture Overview Toga uses a backend-agnostic architecture. The core library defines abstract widget interfaces and a layout engine. Each platform backend (toga-cocoa, toga-gtk, toga-winforms, toga-iOS, toga-android) implements these interfaces using the native toolkit. When you create a `toga.Button`, the active backend instantiates the corresponding Cocoa NSButton, GTK Button, or WinForms Button. This design means the Python application code never touches platform APIs directly. ## Self-Hosting & Configuration - Install with `pip install toga` for the current platform's backend automatically - Scaffold a full project with Briefcase: `pip install briefcase && briefcase new` - Briefcase handles packaging into .app bundles (macOS), .msi installers (Windows), AppImage (Linux), or .ipa/.apk (mobile) - Customize app metadata (name, icon, bundle identifier) in `pyproject.toml` - Install additional backends manually for cross-compilation: `pip install toga-gtk` on Linux, `pip install toga-cocoa` on macOS ## Key Features - True native widgets: apps inherit the host OS's look, feel, and accessibility features automatically - Pack layout engine provides CSS-like flexbox positioning without complex geometry management - Briefcase integration packages Python apps as standalone native installers for every target platform - Mobile support: deploy the same Python codebase as iOS and Android apps via BeeWare tooling - Active community with regular releases and CPython core developer involvement in the project ## Comparison with Similar Tools - **Tkinter** — Python standard library GUI with Tcl/Tk widgets; Toga uses truly native platform controls for a more polished look - **PyQt / PySide** — Feature-rich but complex; Toga is simpler and avoids Qt's licensing considerations - **Kivy** — Custom-rendered touch-focused UI; Toga uses native widgets for platform-authentic desktop apps - **Dear PyGui** — GPU-rendered immediate-mode framework for tools; Toga targets conventional application UIs with native widgets - **wxPython** — Wraps wxWidgets for native look; Toga is a more Pythonic, modern API with mobile support and Briefcase packaging ## FAQ **Q: Can Toga really build iOS and Android apps in Python?** A: Yes. Through BeeWare's Briefcase tool and platform bridges (Rubicon ObjC for iOS, Chaquopy integration for Android), you can package and deploy Toga apps to mobile devices. **Q: Is Toga production-ready?** A: Toga is suitable for many application types and is improving rapidly. Desktop backends (macOS, Linux, Windows) are the most mature; mobile backends are functional but still evolving. **Q: How do I distribute a Toga app to end users?** A: Use Briefcase to package the app: `briefcase build` then `briefcase package` creates native installers (.dmg, .msi, .AppImage, .apk, .ipa) that include a bundled Python runtime. **Q: Does Toga support custom styling or themes?** A: Toga intentionally delegates styling to the native platform. You control layout with Pack but visual appearance follows OS conventions for consistency. ## Sources - https://github.com/beeware/toga - https://toga.readthedocs.io/ --- Source: https://tokrepo.com/en/workflows/asset-699ec4d2 Author: Script Depot