Text formatting, layout and display.
This module provides classes for loading styled documents from text files, HTML files and a pyglet-specific markup format. Documents can be styled with multiple fonts, colours, styles, text sizes, margins, paragraph alignments, and so on.
Using the layout classes, documents can be laid out on a single line or word-wrapped to fit a rectangle. A layout can then be efficiently drawn in a window or updated incrementally (for example, to support interactive text editing).
The label classes provide a simple interface for the common case where an application simply needs to display some text in a window.
A plain text label can be created with:
label = pyglet.text.Label('Hello, world',
font_name='Times New Roman',
font_size=36,
x=10, y=10)
Alternatively, a styled text label using HTML can be created with:
label = pyglet.text.HTMLLabel('<b>Hello</b>, <i>world</i>',
x=10, y=10)
Either label can then be drawn at any time with:
label.draw()
For details on the subset of HTML supported, see pyglet.text.formats.html.
Refer to the Programming Guide for advanced usage of the document and layout classes, including interactive editing, embedding objects within documents and creating scrollable layouts.
Note
Since pyglet 1.1
caret | Provides keyboard and mouse editing procedures for text layout. |
document | Formatted and unformatted document interfaces used by text layout. |
formats | Document formats. |
layout | Render simple text and formatted documents efficiently. |
runlist | Run list encoding utilities. |
DocumentDecoder | Abstract document decoder. |
DocumentLabel | Base label class. |
HTMLLabel | HTML formatted text label. |
Label | Plain text label. |
DocumentDecodeException | An error occurred decoding document text. |
decode_attributed(text) | Create a document directly from some attributed text. |
decode_html(text[, location]) | Create a document directly from some HTML formatted text. |
decode_text(text) | Create a document directly from some plain text. |
get_decoder(filename[, mimetype]) | Get a document decoder for the given filename and MIME type. |
load(filename[, file, mimetype]) | Load a document from a file. |
Defined