Pyglet

{{Notability|date=April 2024}}

{{More citations needed|date=April 2024}}

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.{{Cite book |last=Briggs |first=Anthony |url=https://books.google.com/books?id=4zozEAAAQBAJ&dq=%22Pyglet%22+-wikipedia&pg=PT390 |title=Hello! Python |date=2012-02-12 |publisher=Simon and Schuster |isbn=978-1-63835-152-8 |language=en}}{{Cite book |last1=Paz |first1=Alejandro Rodas de |url=https://books.google.com/books?id=99lOCwAAQBAJ&dq=%22Pyglet%22+-wikipedia&pg=PA29 |title=Python Game Programming By Example |last2=Howse |first2=Joseph |date=2015-09-28 |publisher=Packt Publishing Ltd |isbn=978-1-78528-391-8 |language=en}} 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.{{Cite web |last=Choudhury |first=Ambika |date=2020-06-12 |title=Top Python Frameworks For Game Development |url=https://analyticsindiamag.com/top-9-python-frameworks-for-game-development/ |access-date=2024-04-12 |website=Analytics India Magazine |language=en-US}}

Text display and formatting

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

Image and sprite work

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

Graphics

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

Events and file system

  • Resource management (pyglet.resource)
  • Clock for processing events and time (pyglet.clock.Clock)
  • Window events (pyglet.window.Window)
  • Event dispatching (pyglet.event.EventDispatcher)
  • 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

from pyglet.window import Window

from pyglet.app import run

window = Window(caption="Hello world!", width=640, height=480)

run()

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

{{Portal|Free and open-source software|Video games}}

References

{{Reflist}}