The app is the main entry point and container for the Toga GUI.
The app class is used by instantiating with a name, namespace and callback to a startup delegate which takes 1 argument of the app instance.
To start a UI loop, call
import toga def build(app): # build UI pass if __name__ == '__main__': app = toga.App('First App', 'org.beeware.helloworld', startup=build) app.main_loop()
Alternatively, you can subclass App and implement the startup method
import toga class MyApp(toga.App): def startup(self): # build UI pass if __name__ == '__main__': app = MyApp('First App', 'org.beeware.helloworld') app.main_loop()
- class toga.app.App(formal_name=None, app_id=None, app_name=None, id=None, icon=None, author=None, version=None, home_page=None, description=None, startup=None, windows=None, on_exit=None, factory=None)#
The App is the top level of any GUI program. It is the manager of all the other bits of the GUI app: the main window and events that window generates like user input.
When you create an App you need to provide it a name, an id for uniqueness (by convention, the identifier is a reversed domain name.) and an optional startup function which should run once the App has initialized. The startup function typically constructs some initial user interface.
If the name and app_id are not provided, the application will attempt to find application metadata. This process will determine the module in which the App class is defined, and look for a
.dist-infofile matching that name.
Once the app is created you should invoke the main_loop() method, which will hand over execution of your program to Toga to make the App interface do its thing.
The absolute minimum App would be:
>>> app = toga.App(formal_name='Empty App', app_id='org.beeware.empty') >>> app.main_loop()
formal_name – The formal name of the application. Will be derived from packaging metadata if not provided.
app_id – The unique application identifier. This will usually be a reversed domain name, e.g.
org.beeware.myapp. Will be derived from packaging metadata if not provided.
app_name – The name of the Python module containing the app. Will be derived from the module defining the instance of the App class if not provided.
id – The DOM identifier for the app (optional)
icon – Identifier for the application’s icon.
author – The person or organization to be credited as the author of the application. Will be derived from application metadata if not provided.
version – The version number of the app. Will be derived from packaging metadata if not provided.
home_page – A URL for a home page for the app. Used in auto-generated help menu items. Will be derived from packaging metadata if not provided.
description – A brief (one line) description of the app. Will be derived from packaging metadata if not provided.
startup – The callback method before starting the app, typically to add the components. Must be a
callablethat expects a single argument of
windows – An iterable with objects of
Windowthat will be the app’s secondary windows.
Display the About dialog for the app.
Default implementation shows a platform-appropriate about dialog using app metadata. Override if you want to display a custom About dialog.
Schedule a task to run in the background.
Schedules a coroutine or a generator to run in the background. Control will be returned to the event loop during await or yield statements, respectively. Use this to run background tasks without blocking the GUI. If a regular callable is passed, it will be called as is and will block the GUI until the call returns.
handler – A coroutine, generator or callable.
- app = None#
- property app_id#
The identifier for the app.
This is a reversed domain name, often used for targeting resources, etc.
The identifier as a
- property app_name#
The machine-readable, PEP508-compliant name of the app.
The machine-readable app name, as a
The author of the app. This may be an organization name.
The author of the app, as a
- property current_window#
Return the currently active content window.
- property description#
A brief description of the app.
A brief description of the app, as a
Quit the application gracefully.
Exit full screen mode.
- property formal_name#
The formal name of the app.
The formal name of the app, as a
Hide cursor from view.
- property home_page#
The URL of a web page for the app.
The URL of the app’s home page, as a
- property icon#
The Icon for the app.
toga.Iconinstance for the app’s icon.
- property id#
The DOM identifier for the app.
This id can be used to target CSS directives.
A DOM identifier for the app.
- property is_full_screen#
Is the app currently in full screen mode?
Invoke the application to handle user input.
This method typically only returns once the application is exiting.
- property main_window#
The main window for the app.
The main Window of the app.
- property module_name#
The module name for the app.
The module name for the app, as a
- property name#
The formal name of the app.
The formal name of the app, as a
- property on_exit#
The handler to invoke before the application exits.
callablethat is called on application exit.
- property paths#
Paths for platform appropriate locations on the user’s file system.
Some platforms do not allow arbitrary file access to any location on disk; even when arbitrary file system access is allowed, there are “preferred” locations for some types of content.
pathsobject has a set of sub-properties that return
pathlib.Pathinstances of platform-appropriate paths on the file system.
app – The directory containing the app’s
__main__module. This location should be considered read-only, and only used to retrieve app-specific resources (e.g., resource files bundled with the app).
data – Platform-appropriate location for user data (e.g., user settings)
cache – Platform-appropriate location for temporary files. It should be assumed that the operating system will purge the contents of this directory without warning if it needs to recover disk space.
logs – Platform-appropriate location for log files for this app.
toga – The path of the
togacore module. This location should be considered read-only.
Make one or more windows full screen.
Full screen is not the same as “maximized”; full screen mode is when all window borders and other chrome is no longer visible.
windows – The list of windows to go full screen, in order of allocation to screens. If the number of windows exceeds the number of available displays, those windows will not be visible. If no windows are specified, the app will exit full screen mode.
Create and show the main window for the application.
- property version#
The version number of the app.
The version number of the app, as a
Open the application’s homepage in the default browser.
If the application metadata doesn’t define a homepage, this is a no-op.
- property widgets#
The widgets collection of the entire app.
Can be used to lookup widgets over the entire app through widget id or manually iterating through it. Example:
The reference to the widgets collection of the entire app.