Class pyglet.font.Text

Simple displayable text.

This is a convenience class for rendering strings of text. It takes care of caching the vertices so the text can be rendered every frame with little performance penalty.

Text can be word-wrapped by specifying a width to wrap into. If the width is not specified, it gives the width of the text as laid out.

Deprecated: Use pyglet.text.Label.

Methods

  __init__(self, font, text='', x=0, y=0, z=0, color=(1, 1, 1, 1), width=None, halign='left', valign='baseline')
Create displayable text.
  draw(self)

Properties

  font
  color
  z
float width
Width of the text.
float height
Height of the text.
str text
Text to render.
str halign
Horizontal alignment of the text.
str valign
Vertical alignment of the text.
int leading
Vertical space between adjacent lines, in pixels.
int line_height
Vertical distance between adjacent baselines, in pixels.

Instance Variables

int x
X coordinate of the text
int y
Y coordinate of the text

Constants

  LEFT = 'left'
Align the left edge of the text to the given X coordinate.
  CENTER = 'center'
Align the horizontal center of the text to the given X coordinate.
  RIGHT = 'right'
Align the right edge of the text to the given X coordinate.
  BOTTOM = 'bottom'
Align the bottom of the descender of the final line of text with the given Y coordinate.
  BASELINE = 'baseline'
Align the baseline of the first line of text with the given Y coordinate.
  TOP = 'top'
Align the top of the ascender of the first line of text with the given Y coordinate.

Method Details

__init__

(Constructor) __init__(self, font, text='', x=0, y=0, z=0, color=(1, 1, 1, 1), width=None, halign='left', valign='baseline')
Create displayable text.
Parameters:
font : Font
Font to render the text in.
text : str
Initial string to render.
x : float
X coordinate of the left edge of the text.
y : float
Y coordinate of the baseline of the text. If the text is word-wrapped, this refers to the first line of text.
z : float
Z coordinate of the text plane.
color : 4-tuple of float
Color to render the text in. Alpha values can be specified in the fourth component.
width : float
Width to limit the rendering to. Text will be word-wrapped if necessary.
halign : str
Alignment of the text. See Text.halign for details.
valign : str
Controls positioning of the text based off the y coordinate. One of BASELINE, BOTTOM, CENTER or TOP. Defaults to BASELINE.

Property Details

font

color

z

width

Width of the text.

When set, this enables word-wrapping to the specified width. Otherwise, the width of the text as it will be rendered can be determined.

Type:
float

height

Height of the text.

This property is the ascent minus the descent of the font, unless there is more than one line of word-wrapped text, in which case the height takes into account the line leading. Read-only.

Type:
float

text

Text to render.

The glyph vertices are only recalculated as needed, so multiple changes to the text can be performed with no performance penalty.

Type:
str

halign

Horizontal alignment of the text.

The text is positioned relative to x and width according to this property, which must be one of the alignment constants LEFT, CENTER or RIGHT.

Type:
str

valign

Vertical alignment of the text.

The text is positioned relative to y according to this property, which must be one of the alignment constants BOTTOM, BASELINE, CENTER or TOP.

Type:
str

leading

Vertical space between adjacent lines, in pixels.
Type:
int

line_height

Vertical distance between adjacent baselines, in pixels.
Type:
int

Instance Variable Details

x

X coordinate of the text

y

Y coordinate of the text