my-server
← Wiki

Pyglet

Pyglet is a library for the Python programming language that provides an object-oriented application programming interface for the creation of games and other multimedia applications. pyglet runs on Microsoft Windows, macOS, and Linux; it is released under the BSD Licence. pyglet was first created by Alex Holkner.

Features

Pyglet is written entirely in Python. Images, video, and sound files in a range of formats can be done natively but can also be expanded with the libav and ffmpeg libraries. It requires no external dependencies.

Text display and formatting

  • Rich text formatting (bold, italic, <u>underline</u>, color change, background color, indent, lists) (<code>pyglet.text.formats</code>)
  • Built-in layouts to support editable text
  • Carets (<code>pyglet.text.caret.Caret</code>)
  • HTML support (<code>pyglet.text.layout.IncrementalTextLayout</code>)

Image and sprite work

  • Fast image processing and rendering
  • Built-in sprites (<code>pyglet.sprite</code>)
  • Animated images (<code>*.gif</code>)

Graphics

  • OpenGL shaders supported
  • Simple built-in shapes (rectangles, circles, triangles) (<code>pyglet.shapes</code>)
  • Batched rendering (<code>pyglet.graphics.Batch</code>)
  • 3D model rendering

Events and file system

  • Resource management (<code>pyglet.resource</code>)
  • Clock for processing events and time (<code>pyglet.clock.Clock</code>)
  • Window events (<code>pyglet.window.Window</code>)
  • Event dispatching (<code>pyglet.event.EventDispatcher</code>)
  • Context management

Sprites, text layouts, and text functions are implemented. Multi-level lists are supported and can be created using HTML. Different sections of the displayed document can have distinct styles. A built-in caret provides support for text editing, resembling many features of a UI text input caret.

Example

In this example, lines 1-2 import the pyglet module's necessary components. Line 4 creates a window, and line 6 calls pyglet to run its event loop. Optionally an update rate (in frames per second) can be specified in a rate parameter.

See also

References

External links