pyglet.font

Load fonts and render text.

This is a fairly-low level interface to text rendering. Obtain a font using load:

from pyglet import font
arial = font.load('Arial', 14, bold=True, italic=False)

pyglet will load any system-installed fonts. You can add additional fonts (for example, from your program resources) using add_file or add_directory.

Obtain a list of Glyph objects for a string of text using the Font object:

text = 'Hello, world!'
glyphs = arial.get_glyphs(text)

The most efficient way to render these glyphs is with a GlyphString:

glyph_string = GlyphString(text, glyphs)
glyph_string.draw()

There are also a variety of methods in both Font and GlyphString to facilitate word-wrapping.

A convenient way to render a string of text is with a Text:

text = Text(font, text)
text.draw()

See the pyglet.font.base module for documentation on the base classes used by this package.

Modules

ttf Implementation of the Truetype file format.

Classes

GlyphString An immutable string of glyphs that can be rendered quickly.
Text Simple displayable text.

Functions

add_directory(dir) Add a directory of fonts to pyglet’s search path.
add_file(font) Add a font to pyglet’s search path.
have_font(name) Check if specified system font name is available.
load([name, size, bold, italic, dpi]) Load a font for rendering.

Variables

image = <pyglet._ModuleProxy object at 0x89c116c>
window = <pyglet._ModuleProxy object at 0x89c0f2c>

Notes

Defined

  • base
  • gl
  • glext_arb
  • glu
  • lib
  • lib_glx
  • math
  • os
  • pyglet
  • sys
  • weakref

Table Of Contents

Previous topic

EventException

Next topic

pyglet.font.ttf