Skip to content

Static

A widget which displays static content. Can be used for Rich renderables and can also be the base for other types of widgets.

  • Focusable
  • Container

Example

The example below shows how you can use a Static widget as a simple text label (but see Label as a way of displaying text).

StaticApp Hello, world!

from textual.app import App, ComposeResult
from textual.widgets import Static


class StaticApp(App):
    def compose(self) -> ComposeResult:
        yield Static("Hello, world!")


if __name__ == "__main__":
    app = StaticApp()
    app.run()

Reactive Attributes

This widget has no reactive attributes.

Messages

This widget posts no messages.

Bindings

This widget has no bindings.

Component Classes

This widget has no component classes.

See Also


Bases: Widget

A widget to display simple static content, or use as a base class for more complex widgets.

Parameters:

Name Type Description Default
content VisualType

A Content object, Rich renderable, or string containing console markup.

''
expand bool

Expand content if required to fill container.

False
shrink bool

Shrink content if required to fill container.

False
markup bool

True if markup should be parsed and rendered.

True
name str | None

Name of widget.

None
id str | None

ID of Widget.

None
classes str | None

Space separated list of class names.

None
disabled bool

Whether the static is disabled or not.

False

content property writable

content: VisualType

The original content set in the constructor.

visual property

visual: Visual

The visual to be displayed.

Note that the visual is what is ultimately rendered in the widget, but may not be the same object set with the update method or content property. For instance, if you update with a string, then the visual will be a Content instance.

update

update(content='', *, layout=True)

Update the widget's content area with a string, a Visual (such as Content), or a Rich renderable.

Parameters:

Name Type Description Default
content VisualType

New content.

''
layout bool

Also perform a layout operation (set to False if you are certain the size won't change).

True