pdwidgets.widgets.label

Text label widget.

class pdwidgets.widgets.label.Label(parent, x=0, y=0, w=None, h=None, align=None, align_to=None, fg=None, bg=None, visible=True, value=None, padding=None, text_height=16, scale=1, inverted=False, font_data=None, font=None)[source]

Bases: Widget

Text display using romfont or an optional proportional font.

draw(_=None)[source]

Draw the label’s text on the screen, using absolute coordinates. Optionally fills the background first if bg is set.

text_width(text=None)[source]

Return the pixel width of text without drawing.

Uses this label’s current typeface settings: proportional font when set, otherwise the romfont at text_height / scale (and optional font_data). Defaults to measuring value.

Newlines are not special-cased (same contract as pygraphics.Font.text_width / write_width).

Parameters:

text (str | None) – String to measure; None uses self.value.

Returns:

int – Width in pixels.

property char_width

Rendered character width in pixels.

property char_height

Rendered character height in pixels.