Simple text rendering

The following complete example creates a window that displays "Hello, World" centered vertically and horizontally:

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()

The example demonstrates the most common uses of text rendering: