Skip to content

Pretty

Display a pretty-formatted object.

  • Focusable
  • Container

Example

The example below shows a pretty-formatted dict, but Pretty can display any Python object.

PrettyExample { 'title''Back to the Future', 'releaseYear'1985, 'director''Robert Zemeckis', 'genre''Adventure, Comedy, Sci-Fi', 'cast'[ {'actor''Michael J. Fox''character''Marty McFly'}, {'actor''Christopher Lloyd''character''Dr. Emmett Brown'} ] }

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

DATA = {
    "title": "Back to the Future",
    "releaseYear": 1985,
    "director": "Robert Zemeckis",
    "genre": "Adventure, Comedy, Sci-Fi",
    "cast": [
        {"actor": "Michael J. Fox", "character": "Marty McFly"},
        {"actor": "Christopher Lloyd", "character": "Dr. Emmett Brown"},
    ],
}


class PrettyExample(App):
    def compose(self) -> ComposeResult:
        yield Pretty(DATA)


app = PrettyExample()

if __name__ == "__main__":
    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.


Bases: Widget

A pretty-printing widget.

Used to pretty-print any object.

Parameters:

Name Type Description Default

object

Any

The object to pretty-print.

required

name

str | None

The name of the pretty widget.

None

id

str | None

The ID of the pretty in the DOM.

None

classes

str | None

The CSS classes of the pretty.

None

update

update(object)

Update the content of the pretty widget.

Parameters:

Name Type Description Default

object

Any

The object to pretty-print.

required