HOME

TheInfoList



OR:

pyglet is a
library A library is a collection of materials, books or media that are accessible for use and not just for display purposes. A library provides physical (hard copies) or digital access (soft copies) materials, and may be a physical location or a vir ...
for the
Python Python may refer to: Snakes * Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia ** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia * Python (mythology), a mythical serpent Computing * Python (pro ...
programming language A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language. The description of a programming ...
that provides an
object-oriented Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form of pro ...
application programming interface An application programming interface (API) is a way for two or more computer programs to communicate with each other. It is a type of software interface, offering a service to other pieces of software. A document or standard that describes how t ...
for the creation of games and other multimedia
applications Application may refer to: Mathematics and computing * Application software, computer software designed to help the user to perform specific tasks ** Application layer, an abstraction layer that specifies protocols and interface methods used in a c ...
. pyglet runs on
Microsoft Windows Windows is a group of several proprietary graphical operating system families developed and marketed by Microsoft. Each family caters to a certain sector of the computing industry. For example, Windows NT for consumers, Windows Server for serv ...
,
macOS macOS (; previously OS X and originally Mac OS X) is a Unix operating system developed and marketed by Apple Inc. since 2001. It is the primary operating system for Apple's Mac computers. Within the market of desktop and lapt ...
, and
Linux Linux ( or ) is a family of open-source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically packaged as a Linux distribution, which ...
; it is released under the
BSD Licence BSD licenses are a family of permissive free software licenses, imposing minimal restrictions on the use and distribution of covered software. This is in contrast to copyleft licenses, which have share-alike requirements. The original BSD lice ...
. pyglet was first created by Alex Holkner. It supports windowed and full-screen operations as well as multiple monitors. Images, video, and sound files in a range of formats can be done natively, with more additional capabilities supplied by the optional AVbin plugin, which uses the
Libav Libav is an abandoned free software project, forked from FFmpeg in 2011, that contains libraries and programs for handling multimedia data. History Fork from FFmpeg The Libav project was a fork of the FFmpeg project. It was announced on ...
package to provide support for audio formats including
MP3 MP3 (formally MPEG-1 Audio Layer III or MPEG-2 Audio Layer III) is a coding format for digital audio developed largely by the Fraunhofer Society in Germany, with support from other digital scientists in the United States and elsewhere. Origin ...
,
Ogg Ogg is a free, open container format maintained by the Xiph.Org Foundation. The authors of the Ogg format state that it is unrestricted by software patents and is designed to provide for efficient streaming and manipulation of high-quality d ...
/Vorbis
, and
Windows Media Audio Windows Media Audio (WMA) is a series of audio codecs and their corresponding audio coding formats developed by Microsoft. It is a proprietary technology that forms part of the Windows Media framework. WMA consists of four distinct codecs. The or ...
, and video formats such as DivX,
MPEG-2 MPEG-2 (a.k.a. H.222/H.262 as was defined by the ITU) is a standard for "the generic video coding format, coding of moving pictures and associated audio information". It describes a combination of Lossy compression, lossy video compression and ...
,
H.264 Advanced Video Coding (AVC), also referred to as H.264 or MPEG-4 Part 10, is a video compression standard based on block-oriented, motion-compensated coding. It is by far the most commonly used format for the recording, compression, and distr ...
,
WMV Windows Media Video (WMV) is a series of video codecs and their corresponding video coding formats developed by Microsoft. It is part of the Windows Media framework. WMV consists of three distinct codecs: The original video compression technology ...
, and
XviD Xvid (formerly "XviD") is a video codec library following the MPEG-4 video coding standard, specifically MPEG-4 Part 2 Advanced Simple Profile (ASP). It uses ASP features such as b-frames, global and quarter pixel motion compensation, lumi mas ...
. An advantage of pyglet over many other libraries is that it requires no external dependencies, and uses the ctypes library, a pure-Python C compiler. It builds on
OpenGL OpenGL (Open Graphics Library) is a cross-language, cross-platform application programming interface (API) for rendering 2D and 3D vector graphics. The API is typically used to interact with a graphics processing unit (GPU), to achieve hardwa ...
.


Comparison to other libraries


Pygame

pygame is another library used for making games and is much more widely known than pyglet. This is what it would take to display the window shown in the example. It takes more lines of code and also is harder to understand. Compared to pyglet, pygame is not object-oriented and has less functionality. For example, there is no rich and formatted text, fast drawing commands, etc. The graphics and images have to be drawn again and again and can not be cached. This is one of the performance features of object-oriented programming, where most of the steps do not have to be repeated import pygame screen = pygame.display.set_mode((640, 480)) pygame.display.set_caption("Hello world!") running = True while running: for event in pygame.event.get(): if event.type in pygame.QUIT: running = False pygame.quit()


Features

As a multimedia library, pyglet comes with batteries included. Using OpenGL gives it speed benefits, and is also written entirely in Python, meaning no external dependencies that have to be installed. The ffmpeg library can be optionally installed to support more audio formats. 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 dispatchers for your own event dispatching (pyglet.event.EventDispatcher) * Context management These features make pyglet much faster than many other multimedia libraries. Batched rendering is a technique to draw multiple objects with the same amount of time. Batches support Sprites, images, and TextLayouts, which are the basis for all labels and text. Text functions are implemented as well. Multi-level lists are supported, and can be made using HTML. Different parts of the displayed document can have different styles. A caret is built-in for support for editing text. It resembles many of the 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

*
Pygame Pygame is a cross-platform set of Python modules designed for writing video games. It includes computer graphics and sound libraries designed to be used with the Python programming language. History Pygame was originally written by Pete Shinners ...
, another Python game API, a layer over
Simple DirectMedia Layer Simple DirectMedia Layer (SDL) is a cross-platform software development library designed to provide a hardware abstraction layer for computer multimedia hardware components. Software developers can use it to write high-performance computer games ...
*
Kivy (framework) Kivy is a free and open source Python framework for developing mobile apps and other multitouch application software with a natural user interface (NUI). It is distributed under the terms of the MIT License, and can run on Android, iOS, Lin ...
, a Python OpenGL-based UI for multitouch interactions *
Cocos2d Cocos2d is a free software framework. It can be used to build games, apps and other cross platform GUI based interactive programs. Cocos2d contains many branches with the best known being Cocos2d-objc, Cocos2d-x, Cocos2d-html5 and Cocos2d-XN ...
*
Panda3D Panda3D is a game engine that includes graphics, audio, I/O, collision detection, and other abilities relevant to the creation of 3D games. Panda3D is free, open-source software under the revised BSD license. Panda3D's intended game-development ...


External links

*{{Official website, http://www.pyglet.org/
Official documentation

pyglet's project page
on
GitHub GitHub, Inc. () is an Internet hosting service for software development and version control using Git. It provides the distributed version control of Git plus access control, bug tracking, software feature requests, task management, continuous ...

AVbin
pyglet's wrapper for Libav Python (programming language) libraries