Skip to content

textual.app

Here you will find the App class, which is the base class for Textual apps.

See app basics for how to build Textual apps.

AutopilotCallbackType module-attribute

AutopilotCallbackType = (
    "Callable[[Pilot[object]], Coroutine[Any, Any, None]]"
)

Signature for valid callbacks that can be used to control apps.

CommandCallback module-attribute

CommandCallback = (
    "Callable[[], Awaitable[Any]] | Callable[[], Any]"
)

Signature for callbacks used in get_system_commands

RenderResult module-attribute

RenderResult = 'RenderableType | Visual | SupportsVisual'

Result of Widget.render()

ScreenType module-attribute

ScreenType = TypeVar('ScreenType', bound=Screen)

Type var for a Screen, used in get_screen.

ActionError

Bases: Exception

Base class for exceptions relating to actions.

ActiveModeError

Bases: ModeError

Raised when attempting to remove the currently active mode.

App

App(
    driver_class=None,
    css_path=None,
    watch_css=False,
    ansi_color=False,
)

Bases: Generic[ReturnType], DOMNode

The base class for Textual Applications.

Parameters:

Name Type Description Default

driver_class

Type[Driver] | None

Driver class or None to auto-detect. This will be used by some Textual tools.

None

css_path

CSSPathType | None

Path to CSS or None to use the CSS_PATH class variable. To load multiple CSS files, pass a list of strings or paths which will be loaded in order.

None

watch_css

bool

Reload CSS if the files changed. This is set automatically if you are using textual run with the dev switch.

False

ansi_color

bool

Allow ANSI colors if True, or convert ANSI colors to to RGB if False.

False

Raises:

Type Description
CssPathError

When the supplied CSS path(s) are an unexpected type.

ALLOW_IN_MAXIMIZED_VIEW class-attribute

ALLOW_IN_MAXIMIZED_VIEW = 'Footer'

The default value of Screen.ALLOW_IN_MAXIMIZED_VIEW.

ALLOW_SELECT class-attribute

ALLOW_SELECT = True

A switch to toggle arbitrary text selection for the app.

Note that this doesn't apply to Input and TextArea which have builtin support for selection.

AUTO_FOCUS class-attribute

AUTO_FOCUS = '*'

A selector to determine what to focus automatically when a screen is activated.

The widget focused is the first that matches the given CSS selector. Setting to None or "" disables auto focus.

BINDINGS class-attribute

BINDINGS = [
    Binding(
        "ctrl+q",
        "quit",
        "Quit",
        tooltip="Quit the app and return to the command prompt.",
        show=False,
        priority=True,
    ),
    Binding("ctrl+c", "help_quit", show=False, system=True),
]

The default key bindings.

BINDING_GROUP_TITLE class-attribute instance-attribute

BINDING_GROUP_TITLE = None

Set to text to show in the key panel.

CLICK_CHAIN_TIME_THRESHOLD class-attribute

CLICK_CHAIN_TIME_THRESHOLD = 0.5

The maximum number of seconds between clicks to upgrade a single click to a double click, a double click to a triple click, etc.

CLOSE_TIMEOUT class-attribute instance-attribute

CLOSE_TIMEOUT = 5.0

Timeout waiting for widget's to close, or None for no timeout.

COMMANDS class-attribute

Command providers used by the command palette.

Should be a set of command.Provider classes.

COMMAND_PALETTE_BINDING class-attribute

COMMAND_PALETTE_BINDING = 'ctrl+p'

The key that launches the command palette (if enabled by App.ENABLE_COMMAND_PALETTE).

COMMAND_PALETTE_DISPLAY class-attribute

COMMAND_PALETTE_DISPLAY = None

How the command palette key should be displayed in the footer (or None for default).

CSS class-attribute

CSS = ''

Inline CSS, useful for quick scripts. This is loaded after CSS_PATH, and therefore takes priority in the event of a specificity clash.

CSS_PATH class-attribute

CSS_PATH = None

File paths to load CSS from.

DEFAULT_MODE class-attribute

DEFAULT_MODE = '_default'

Name of the default mode.

ENABLE_COMMAND_PALETTE class-attribute

ENABLE_COMMAND_PALETTE = True

Should the command palette be enabled for the application?

ESCAPE_TO_MINIMIZE class-attribute

ESCAPE_TO_MINIMIZE = True

Use escape key to minimize widgets (potentially overriding bindings).

This is the default value, used if the active screen's ESCAPE_TO_MINIMIZE is not changed from None.

HORIZONTAL_BREAKPOINTS class-attribute instance-attribute

HORIZONTAL_BREAKPOINTS = []

List of horizontal breakpoints for responsive classes.

This allows for styles to be responsive to the dimensions of the terminal. For instance, you might want to show less information, or fewer columns on a narrow displays -- or more information when the terminal is sized wider than usual.

A breakpoint consists of a tuple containing the minimum width where the class should applied, and the name of the class to set.

Note that only one class name is set, and if you should avoid having more than one breakpoint set for the same size.

Example
# Up to 80 cells wide, the app has the class "-normal"
# 80 - 119 cells wide, the app has the class "-wide"
# 120 cells or wider, the app has the class "-very-wide"
HORIZONTAL_BREAKPOINTS = [(0, "-normal"), (80, "-wide"), (120, "-very-wide")]

INLINE_PADDING class-attribute

INLINE_PADDING = 1

Number of blank lines above an inline app.

MODES class-attribute

MODES = {}

Modes associated with the app and their base screens.

The base screen is the screen at the bottom of the mode stack. You can think of it as the default screen for that stack. The base screens can be names of screens listed in SCREENS, Screen instances, or callables that return screens.

Example
class HelpScreen(Screen[None]):
    ...

class MainAppScreen(Screen[None]):
    ...

class MyApp(App[None]):
    MODES = {
        "default": "main",
        "help": HelpScreen,
    }

    SCREENS = {
        "main": MainAppScreen,
    }

    ...

NOTIFICATION_TIMEOUT class-attribute

NOTIFICATION_TIMEOUT = 5

Default number of seconds to show notifications before removing them.

SCREENS class-attribute

SCREENS = {}

Screens associated with the app for the lifetime of the app.

SUB_TITLE class-attribute instance-attribute

SUB_TITLE = None

A class variable to set the default sub-title for the application.

To update the sub-title while the app is running, you can set the sub_title attribute. See also the Screen.SUB_TITLE attribute.

SUSPENDED_SCREEN_CLASS class-attribute

SUSPENDED_SCREEN_CLASS = ''

Class to apply to suspended screens, or empty string for no class.

TITLE class-attribute instance-attribute

TITLE = None

A class variable to set the default title for the application.

To update the title while the app is running, you can set the title attribute. See also the Screen.TITLE attribute.

TOOLTIP_DELAY class-attribute instance-attribute

TOOLTIP_DELAY = 0.5

The time in seconds after which a tooltip gets displayed.

VERTICAL_BREAKPOINTS class-attribute instance-attribute

VERTICAL_BREAKPOINTS = []

List of vertical breakpoints for responsive classes.

Contents are the same as HORIZONTAL_BREAKPOINTS, but the integer is compared to the height, rather than the width.

active_bindings property

active_bindings

Get currently active bindings.

If no widget is focused, then app-level bindings are returned. If a widget is focused, then any bindings present in the active screen and app are merged and returned.

This property may be used to inspect current bindings.

Returns:

Type Description
dict[str, ActiveBinding]

A dict that maps keys on to binding information.

animation_level instance-attribute

animation_level = TEXTUAL_ANIMATIONS

Determines what type of animations the app will display.

See textual.constants.TEXTUAL_ANIMATIONS.

animator property

animator

The animator object.

ansi_color class-attribute instance-attribute

ansi_color = Reactive(False)

Allow ANSI colors in UI?

ansi_theme property

ansi_theme

The ANSI TerminalTheme currently being used.

Defines how colors defined as ANSI (e.g. magenta) inside Rich renderables are mapped to hex codes.

ansi_theme_dark class-attribute instance-attribute

ansi_theme_dark = Reactive(MONOKAI, init=False)

Maps ANSI colors to hex colors using a Rich TerminalTheme object while using a dark theme.

ansi_theme_light class-attribute instance-attribute

ansi_theme_light = Reactive(ALABASTER, init=False)

Maps ANSI colors to hex colors using a Rich TerminalTheme object while using a light theme.

app_focus class-attribute instance-attribute

app_focus = Reactive(True, compute=False)

Indicates if the app has focus.

When run in the terminal, the app always has focus. When run in the web, the app will get focus when the terminal widget has focus.

app_resume_signal instance-attribute

app_resume_signal = Signal(self, 'app-resume')

The signal that is published when the app is resumed after a suspend.

When the app is resumed after a App.suspend call this signal will be published; subscribe to this signal to perform work after the app has resumed.

app_suspend_signal instance-attribute

app_suspend_signal = Signal(self, 'app-suspend')

The signal that is published when the app is suspended.

When App.suspend is called this signal will be published; subscribe to this signal to perform work before the suspension takes place.

available_themes property

available_themes

All available themes (all built-in themes plus any that have been registered).

A dictionary mapping theme names to Theme instances.

children property

children

A view onto the app's immediate children.

This attribute exists on all widgets. In the case of the App, it will only ever contain a single child, which will be the currently active screen.

Returns:

Type Description
Sequence['Widget']

A sequence of widgets.

clipboard property

clipboard

The value of the local clipboard.

Note, that this only contains text copied in the app, and not text copied from elsewhere in the OS.

console_options property

console_options

Get options for the Rich console.

Returns:

Type Description
ConsoleOptions

Console options (same object returned from console.options).

current_mode property

current_mode

The name of the currently active mode.

cursor_position instance-attribute

cursor_position = Offset(0, 0)

The position of the terminal cursor in screen-space.

This can be set by widgets and is useful for controlling the positioning of OS IME and emoji popup menus.

debug property

debug

Is debug mode enabled?

default_screen property

default_screen

The default screen instance.

escape_to_minimize property

escape_to_minimize

Use the escape key to minimize?

When a widget is maximized, this boolean determines if the escape key will minimize the widget (potentially overriding any bindings).

The default logic is to use the screen's ESCAPE_TO_MINIMIZE classvar if it is set to True or False. If the classvar on the screen is not set (and left as None), then the app's ESCAPE_TO_MINIMIZE is used.

focused property

focused

The widget that is focused on the currently active screen, or None.

Focused widgets receive keyboard input.

Returns:

Type Description
Widget | None

The currently focused widget, or None if nothing is focused.

hover_over instance-attribute

hover_over = None

The first widget with a hover style under the mouse.

is_attached property

is_attached

Is this node linked to the app through the DOM?

is_dom_root property

is_dom_root

Is this a root node (i.e. the App)?

is_headless property

is_headless

Is the app running in 'headless' mode?

Headless mode is used when running tests with run_test.

is_inline property

is_inline

Is the app running in 'inline' mode?

is_web property

is_web

Is the app running in 'web' mode via a browser?

log property

log

The textual logger.

Example
self.log("Hello, World!")
self.log(self.tree)

Returns:

Type Description
Logger

A Textual logger.

mouse_over instance-attribute

mouse_over = None

The widget directly under the mouse.

return_code property

return_code

The return code with which the app exited.

Non-zero codes indicate errors. A value of 1 means the app exited with a fatal error. If the app hasn't exited yet, this will be None.

Example

The return code can be used to exit the process via sys.exit.

my_app.run()