pyglet Documentation
Note
This is the documentation for pyglet version 3.0. If you need a different one use the docs version selector.
pyglet is a cross-platform windowing and multimedia library for Python, intended for developing games and other visually rich applications. It supports windowing, user interface event handling, game controllers and joysticks, OpenGL graphics, loading images and videos, and playing sounds and music. pyglet works on Windows, macOS and Linux.
Some of the features of pyglet are:
No external dependencies or installation requirements. For most application and game requirements, pyglet needs nothing else besides Python, simplifying distribution and installation.
Take advantage of multiple windows and multi-monitor desktops. pyglet allows you to use as many windows as you need, and is fully aware of multi-monitor setups for use with fullscreen games and applications.
Load images, sound, music and video in almost any format. pyglet has built-in support for common audio and image formats, and can optionally use ffmpeg to load almost any other compressed audio or video files.
pyglet is provided under the BSD open-source license, allowing you to use it for both commercial and other open-source projects with very little restriction.
Please join the conversation on our Discord server.!
If this is your first time reading about pyglet, we suggest you start at Writing a pyglet application. If you are migrating from an older version of pyglet, please read through Migrating from pyglet 2.1 to pyglet 3.0.
Getting Started
Application Fundamentals
- Windowing
- The application event loop
- Event dispatching & handling
- Event chains
- Keeping track of time
- Runtime Options
OptionsOptions.audioOptions.backendOptions.com_mtaOptions.debug_apiOptions.debug_api_shadersOptions.debug_api_traceOptions.debug_api_trace_argsOptions.debug_comOptions.debug_fontOptions.debug_graphics_batchOptions.debug_inputOptions.debug_libOptions.debug_mediaOptions.debug_waylandOptions.debug_win32Options.debug_x11Options.dpi_scalingOptions.font_name_compatibilityOptions.headlessOptions.headless_deviceOptions.opengl_persistent_buffersOptions.optimize_statesOptions.osx_alt_loopOptions.osx_displaylinkOptions.pyodideOptions.search_local_libsOptions.shader_bind_managementOptions.text_antialiasingOptions.text_shapingOptions.vsyncOptions.waylandOptions.win32_disable_xinputOptions.win32_gdi_fontOptions.xlib_fullscreen_override_redirectOptions.xsync
options- Environment settings
- Debugging tools
Input and User Interface
Assets and Media
- Application resources
- Images and Image Data
- Supported fonts
- Displaying text
- Playing Sound and Video
Graphics and Rendering
- Drawing Shapes
- Textures and Rendering
- Shaders and Rendering
- Cameras and Views
- What a camera manages
- Default camera behavior
- Creating 2D and 3D cameras
- Multiple cameras and views
- Creating views
- Using camera scopes with batches
- Using camera scopes in groups
- When camera changes are applied
- Custom shader integration
- OpenGL 2 and OpenGL ES 2 shaders
- Viewport
- Coordinate conversion
- Scissor
- Matrix and Vector Math
- 3D Models and Scenes
Graphics Backends
Web and Migration
- Pyodide and browsers
- Migrating from pyglet 2.1 to 3.0
- Introduction
- pyglet.gl reorganization
- Enum-based graphics constants
- Shader vertex formats
- Image changes and removal of image.blit
- Separation of Media Players
- SourceGroup removal
- Loading resources before Window creation
- Migrating custom cameras
- pyglet.graphics.Group changes
- UI manager, widgets, and layouts
- Other notable API changes
- Migrating from pyglet 2.0 to 2.1
- From pygame to pyglet
- Benefits to switching
- Coordinate system
- Event loop: polling vs event-driven
- Input handling
- Clock and scheduling
- Surfaces vs images and textures
- Transparency and image loading
- Blitting vs drawing and batching
- Geometry lifetime: recreate every frame vs reuse
- Collision and
Rectmigration - Minimal migration checklist
API Reference
- pyglet
- pyglet.app
- pyglet.clock
- Scheduling
- Using multiple clocks
ChainStoppedChainChainGroupClockClock.sleep()Clock.call_scheduled_functions()Clock.chain()Clock.create_group()Clock.get_frequency()Clock.get_sleep_time()Clock.parallel()Clock.race()Clock.repeat()Clock.repeat_duration()Clock.repeat_forever()Clock.repeat_until()Clock.schedule()Clock.schedule_interval()Clock.schedule_interval_fixed_delay()Clock.schedule_interval_for_duration()Clock.schedule_interval_soft()Clock.schedule_once()Clock.tick()Clock.timeout()Clock.tween()Clock.unschedule()Clock.update_time()Clock.times
YieldInstructionYieldingOperationchain()ease_in()ease_in_out()ease_out()from_callback()get_default()get_frequency()get_sleep_time()linear()parallel()race()repeat()repeat_duration()repeat_forever()repeat_until()schedule()schedule_interval()schedule_interval_fixed_delay()schedule_interval_for_duration()schedule_interval_soft()schedule_once()set_default()smoothstep()tick()timeout()tween()unschedule()wait_for_event()yielding_callback()STOPPED
- pyglet.config
- pyglet.display
- pyglet.customtypes
- pyglet.enums
AddressModeAnchorAnimationChannelTargetPathAnimationInterpolationBlendFactorBlendFactor.CONSTANT_ALPHABlendFactor.CONSTANT_COLORBlendFactor.DST_ALPHABlendFactor.DST_COLORBlendFactor.ONEBlendFactor.ONE_MINUS_CONSTANT_ALPHABlendFactor.ONE_MINUS_CONSTANT_COLORBlendFactor.ONE_MINUS_DST_ALPHABlendFactor.ONE_MINUS_DST_COLORBlendFactor.ONE_MINUS_SRC_ALPHABlendFactor.ONE_MINUS_SRC_COLORBlendFactor.SRC_ALPHABlendFactor.SRC_COLORBlendFactor.ZERO
BlendOpCompareOpComponentFormatCullFaceFramebufferAttachmentFramebufferAttachment.COLOR0FramebufferAttachment.COLOR1FramebufferAttachment.COLOR10FramebufferAttachment.COLOR11FramebufferAttachment.COLOR12FramebufferAttachment.COLOR13FramebufferAttachment.COLOR14FramebufferAttachment.COLOR15FramebufferAttachment.COLOR2FramebufferAttachment.COLOR3FramebufferAttachment.COLOR4FramebufferAttachment.COLOR5FramebufferAttachment.COLOR6FramebufferAttachment.COLOR7FramebufferAttachment.COLOR8FramebufferAttachment.COLOR9FramebufferAttachment.DEPTHFramebufferAttachment.DEPTH_STENCILFramebufferAttachment.STENCIL
FramebufferTargetFrontFaceGeometryModeGraphicsAPIPixelFormatStencilOpStretchStyleTextureFilterTextureTypeTextureWrappingWeight
- pyglet.event
- Event types
- Attaching event handlers
- Event handler stack
- Dispatching events
EventExceptionHandlerMismatchExceptionEventDispatcherEventDispatcher.register_event_type()EventDispatcher.dispatch_event()EventDispatcher.event()EventDispatcher.pop_handlers()EventDispatcher.post_event()EventDispatcher.push_handlers()EventDispatcher.remove_handler()EventDispatcher.remove_handlers()EventDispatcher.set_handler()EventDispatcher.set_handlers()EventDispatcher.event_types
- pyglet.font
- pyglet.graphics
- pyglet.graphics.allocation
- pyglet.graphics.atlas
- pyglet.graphics.draw
- pyglet.graphics.framebuffer
- pyglet.graphics.instance
- pyglet.graphics.shader
MissingAttributeExceptionMissingUniformExceptionShaderExceptionUnsupportedShaderTypeComputeShaderProgramPushConstantsSamplerShaderShaderProgramShaderProgramViewShaderSourceTransformFeedbackShaderProgramUBOBindingManagerUniformArrayBaseUniformBaseUniformBlockUniformBlockDescget_default_shader()
- pyglet.graphics.texture
- pyglet.graphics.vertexbuffer
AbstractBufferAttributeBufferObjectBackedBufferObjectBufferBindingSliceBufferDataStoreBufferRangeCTypeDataStoreDrawIndirectBufferIndexedBindingBufferIndexedBufferObjectMappedBufferObjectPersistentBufferObjectPixelBufferPixelPackBufferPixelUnpackBufferRingBufferShaderStorageBufferTextureBufferTransformFeedbackBufferUniformBufferObjectUniformBufferRegion
- pyglet.graphics.vertexdomain
GraphicsAPIErrorGraphicsBackendErrorGraphicsIntegrationErrorMissingAttributeErrorUnsupportedBackendError
- pyglet.gui
- pyglet.image
- pyglet.info
- Command-line options
dump()dump_al()dump_backend()dump_backend_glx()dump_backend_platform_api()dump_backend_wgl()dump_ffmpeg()dump_gl()dump_gl_platform()dump_glx()dump_graphics_api()dump_graphics_probe()dump_media()dump_media_decoders()dump_platform()dump_pyglet()dump_python()dump_wgl()dump_window()dump_window_and_backend()dump_wintab()main()
- Command-line options
- pyglet.input
- pyglet.math
Mat3Mat4Mat4.from_rotation()Mat4.from_scale()Mat4.from_translation()Mat4.look_at()Mat4.orthogonal_projection()Mat4.perspective_projection()Mat4.column()Mat4.rotate()Mat4.row()Mat4.scale()Mat4.translate()Mat4.transpose()Mat4.aMat4.bMat4.cMat4.dMat4.eMat4.fMat4.gMat4.hMat4.iMat4.jMat4.kMat4.lMat4.mMat4.nMat4.oMat4.p
QuaternionVec2Vec3Vec4clamp()
- pyglet.media
- pyglet.model
- pyglet.resource
- pyglet.storage
- pyglet.sprite
- Drawing multiple sprites
SpriteSprite.group_classSprite.delete()Sprite.draw()Sprite.get_sprite_group()Sprite.on_animation_end()Sprite.update()Sprite.anchorSprite.anchor_positionSprite.anchor_xSprite.anchor_ySprite.batchSprite.blend_modeSprite.colorSprite.event_typesSprite.frame_indexSprite.groupSprite.heightSprite.imageSprite.opacitySprite.pausedSprite.positionSprite.programSprite.rotationSprite.scaleSprite.scale_xSprite.scale_ySprite.visibleSprite.widthSprite.xSprite.ySprite.z
SpriteGroupMultiTextureSpriteMultiTextureSprite.group_classMultiTextureSprite.delete()MultiTextureSprite.get_frame_index()MultiTextureSprite.get_layer()MultiTextureSprite.get_sprite_group()MultiTextureSprite.set_frame_index()MultiTextureSprite.set_layer()MultiTextureSprite.frame_indexMultiTextureSprite.imageMultiTextureSprite.paused
MultiTextureSpriteGroup
- pyglet.shapes
- pyglet.text
- pyglet.text.caret
- pyglet.text.document
- pyglet.text.layout
- Style attributes
IncrementalTextDecorationGroupIncrementalTextLayoutIncrementalTextLayoutGroupScrollableTextDecorationGroupScrollableTextLayoutScrollableTextLayoutGroupTextDecorationGroupTextLayoutTextLayoutGroupget_default_decoration_shader()get_default_image_layout_shader()get_default_layout_shader()
DocumentDecodeExceptionDocumentDecoderDocumentLabelDropShadowHTMLLabelLabelLinearGradientStrokedecode_attributed()decode_html()decode_text()get_decoder()load()
- pyglet.window
External Resources
Development Guide
- Contributing
- Development environment
- Documentation and Type Hints
- Testing pyglet
- Making a pyglet release
- OpenGL Interface Implementation
- ctypes Wrapper Generation
- wraptypes
- Media manual
- Media logging manual