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.


textual.widgets.Pretty class

def __init__(self, object, *, name=None, id=None, classes=None):

Bases: Widget

A pretty-printing widget.

Used to pretty-print any object.

Parameters
Parameter Default Description
object
Any
required

The object to pretty-print.

name
str | None
None

The name of the pretty widget.

id
str | None
None

The ID of the pretty in the DOM.

classes
str | None
None

The CSS classes of the pretty.

update method

def update(self, object):

Update the content of the pretty widget.

Parameters
Parameter Default Description
object
Any
required

The object to pretty-print.