The pyglet.text module can render formatted text efficiently. A new class Label supercedes the old pyglet.font.Text class (which is now actually implemented in terms of Label). The "Hello, World" application can now be written:
window = pyglet.window.Window() label = pyglet.text.Label('Hello, world', font_name='Times New Roman', font_size=36, x=window.width//2, y=window.height//2, halign='center', valign='center') @window.event def on_draw(): window.clear() label.draw() pyglet.app.run()
You can also display multiple fonts and styles within one label, with HTMLLabel:
label = pyglet.text.HTMLLabel('<b>Hello</b>, <font color=red>world!</font>')
More advanced uses of the new text module permit applications to efficiently display large, scrolling, formatted documents (for example, HTML files with embedded images), and to allow the user to interactively edit text as in a WYSIWYG text editor.