{"id":4191,"library":"pyglet","title":"Pyglet","description":"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.","status":"active","version":"2.1.14","language":"en","source_language":"en","source_url":"https://github.com/pyglet/pyglet","tags":["game development","multimedia","graphics","windowing","opengl"],"install":[{"cmd":"pip install pyglet","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Optional dependency for playing a wide variety of compressed audio (MP3, OGG/Vorbis, WMA) and video (MPEG2, H.264, H.265, WMV, Xvid) formats. Built-in support exists for basic formats (wav, png, bmp) without FFmpeg.","package":"FFmpeg","optional":true}],"imports":[{"symbol":"pyglet","correct":"import pyglet"},{"note":"While 'import pyglet' and accessing as pyglet.window.Window() works, explicit import is common for brevity.","wrong":"import pyglet.window as window; window.Window()","symbol":"Window","correct":"from pyglet.window import Window"},{"symbol":"run","correct":"pyglet.app.run()"},{"symbol":"schedule_interval","correct":"pyglet.clock.schedule_interval(func, interval)"}],"quickstart":{"code":"import pyglet\n\nwindow = pyglet.window.Window(800, 600, caption='Hello Pyglet')\nlabel = pyglet.text.Label('Hello, world', font_name='Times New Roman', font_size=36,\n                          x=window.width//2, y=window.height//2,\n                          anchor_x='center', anchor_y='center')\n\n@window.event\ndef on_draw():\n    window.clear()\n    label.draw()\n\npyglet.app.run()","lang":"python","description":"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."},"warnings":[{"fix":"Review and update OpenGL code to utilize modern OpenGL (3.3+) practices. Consult the 'Migrating from pyglet 1.5' guide in the official documentation.","message":"Pyglet 2.0 (and later) requires modern OpenGL (3.3+) context, moving away from legacy OpenGL 2.0. Applications making direct OpenGL 1.x API calls or using older shaders will need significant updates.","severity":"breaking","affected_versions":"2.0.0 and later"},{"fix":"Refer to the 'Migrating from pyglet 2.0' guide in the official documentation for specific changes and updated API usage.","message":"Pyglet 2.1 introduced minor breaking changes to arguments for text, UI, and game controller handling. Locations/names for some features, data types, and math classes (e.g., `pyglet.math.Mat3` and `Mat4` now accept direct arguments instead of an iterable) also changed. The `pyglet.options` module is now accessed as a `pyglet.options` attribute.","severity":"breaking","affected_versions":"2.1.0 and later"},{"fix":"Install FFmpeg on your operating system (e.g., via a package manager like `apt`, `brew`, or by downloading binaries) if you need to play advanced media formats.","message":"To play a wide range of compressed audio (e.g., MP3, OGG/Vorbis, WMA) and video formats (e.g., MPEG2, H.264), FFmpeg must be installed separately on your system. Without it, only basic formats (like WAV, PNG, BMP) are supported.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure your scheduled function signature includes `dt`, e.g., `def update(dt): ...`.","message":"When using `pyglet.clock.schedule_interval()` to schedule a function to run periodically, the scheduled function MUST accept a `dt` (delta time) parameter as its first argument, even if the value is not used within the function.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always include `window.clear()` as the first line within your `on_draw` function.","message":"Forgetting to call `window.clear()` at the beginning of your `on_draw` event handler will result in drawing artifacts from previous frames, as the buffer is not explicitly cleared.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}