Pyglet

2.1.14 · active · verified Sat Apr 11

Pyglet is a cross-platform windowing and multimedia library for Python, designed for developing games and other visually rich applications. It provides robust support for windowing, input event handling (keyboard, mouse, controllers), OpenGL graphics, loading various image and video formats, and playing sounds and music. Compatible with Windows, macOS, and Linux, pyglet is currently at version 2.1.14 and maintains an active development cycle with periodic updates and new releases.

Warnings

Install

Imports

Quickstart

This minimal example opens an 800x600 pixel window displaying 'Hello, world!' centered. It demonstrates window creation, text rendering, event handling via decorator, and starting the application loop.

import pyglet

window = pyglet.window.Window(800, 600, caption='Hello Pyglet')
label = pyglet.text.Label('Hello, world', font_name='Times New Roman', font_size=36,
                          x=window.width//2, y=window.height//2,
                          anchor_x='center', anchor_y='center')

@window.event
def on_draw():
    window.clear()
    label.draw()

pyglet.app.run()

view raw JSON →