Pyglet is easy to use but powerful library for developing visually rich GUI applications like games, multimedia etc on Windows, Mac OS and Linux. This library is created purely in Python and it supports many features like windowing, user interface event handling, Joysticks, OpenGL graphics, loading images, and videos, and playing sounds and music.
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.
- No external dependencies or installation requirements: For development of most of the applications, pyglet does not need any external libraries or installation of packages which helps in simplifying distribution and installation
- Take advantage of multiple windows and multi-monitor desktops: Sometimes multi-monitor desktop setups are use for game development and pyglet is designed in such a way that it lets you use as many windows as needed and also allows fullscreen games and application across multiple screens.
- Load images, sound, music and video in almost any format
- 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.
- It supports development in Python 2 as well as Python 3
Since pyglet is created entirely in Python, no special tasks are needed to be done for installation. pyglet can be install in many ways, the most basic installation requires typing the following command in your terminal:
pip install pyglet
- Begin the program by importing the library:
- Using the default constructor, we can create windows which display the app contents:
new_window = pyglet.window.Window()
Label is created to display the text Hello, World!:
label = pyglet.text.Label('Hello, World !', font_name ='Cooper', font_size = 16, x = new_window.width//2, y = new_window.height//2, anchor_x ='center', anchor_y ='center')
on_draw()event is used to draw its contents on to the window.The pyglet library provides several ways to attach event handlers to objects; a simple way is to use a decorator:
@new_window.event def on_draw(): new_window.clear() label.draw()
- Finally to run the app the following line is appended at the end of the source code:
- Python | Introduction to Web development using Flask
- Introduction to Web Development and the Holy Trinity of it
- Introduction to Postman for API Development
- Python - Read blob object in python using wand library
- Learning Model Building in Scikit-learn : A Python Machine Learning Library
- Pytube | Python library to download youtube videos
- Python Faker Library
- FuzzyWuzzy Python library
- Python | Schedule Library
- Python | Holidays library
- Python math library | expm1() method
- Python math library | gamma() function
- Python math library | isnan() method
- Python math library | exp() method
- Python math library | isfinite() and remainder() method
- Python math library | isclose() method
- Python | Visualize missing values (NaN) values using Missingno Library
- Python Numerizer Library
- Python Pyforest Library
- How to install Librosa Library in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.