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 Postman for API Development
- Introduction to Web Development and the Holy Trinity of it
- FuzzyWuzzy Python library
- Python | Schedule Library
- Python Numerize Library
- Python Faker Library
- Python Pyforest Library
- Python Numerizer Library
- Python | Holidays library
- How to install Librosa Library in Python
- Python math library | exp() method
- Python math library | isclose() method
- Python math library | expm1() method
- Python math library | isnan() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.