Skip to content

Renderables

A collection of Rich renderables which may be returned from a widget's render() method.

Bar class

def __init__(
    self,
    highlight_range=(0, 0),
    highlight_style="magenta",
    background_style="grey37",
    clickable_ranges=None,
    width=None,
):

Thin horizontal bar with a portion highlighted.

Parameters
Parameter Default Description
highlight_range
tuple[float, float]
(0, 0)

The range to highlight.

highlight_style
StyleType
'magenta'

The style of the highlighted range of the bar.

background_style
StyleType
'grey37'

The style of the non-highlighted range(s) of the bar.

width
int | None
None

The width of the bar, or None to fill available width.

Blank class

def __init__(self, color='transparent'):

Draw solid background color.

Digits class

def __init__(self, text, style=''):

Renders a 3X3 unicode 'font' for numerical values.

Parameters
Parameter Default Description
text
str
required

Text to display.

style
StyleType
''

Style to apply to the digits.

get_width classmethod

def get_width(cls, text):

Calculate the width without rendering.

Parameters
Parameter Default Description
text
str
required

Text which may be displayed in the Digits widget.

Returns
Type Description
int

width of the text (in cells).

LinearGradient class

def __init__(self, angle, stops):

Render a linear gradient with a rotation.

Parameters
Parameter Default Description
angle
float
required

Angle of rotation in degrees.

stops
Sequence[tuple[float, Color | str]]
required

List of stop consisting of pairs of offset (between 0 and 1) and color.

VerticalGradient class

def __init__(self, color1, color2):

Draw a vertical gradient.

Sparkline class

def __init__(
    self,
    data,
    *,
    width,
    min_color=Color.from_rgb(0, 255, 0),
    max_color=Color.from_rgb(255, 0, 0),
    summary_function=max
):

Bases: Generic[T]

A sparkline representing a series of data.

Parameters
Parameter Default Description
data
Sequence[T]
required

The sequence of data to render.

width
int | None
required

The width of the sparkline/the number of buckets to partition the data into.

min_color
Color
Color.from_rgb(0, 255, 0)

The color of values equal to the min value in data.

max_color
Color
Color.from_rgb(255, 0, 0)

The color of values equal to the max value in data.

summary_function
SummaryFunction[T]
max

Function that will be applied to each bucket.