Python Pyglet Tutorial | Pyglet Module In Python Tutorial

Chapter 180: Pyglet

Pyglet is a Python module used for visuals and sound. It has no dependencies on other modules. See [][1] for the official information. [1]:

Section 180.1: Installation of Pyglet

Install Python, go into the command line and type:

Python 2:

pip install pyglet

Python 3:

pip3 install pyglet

Section 180.2: Hello World in Pyglet

import pyglet
window = pyglet.window.Window()
label = pyglet.text.Label('Hello, world',
font_name='Times New Roman',
x=window.width//2, y=window.height//2,
anchor_x='center', anchor_y='center')
def on_draw():

Section 180.3: Playing Sound in Pyglet

sound =

Section 180.4: Using Pyglet for OpenGL

import pyglet
from import *
win = pyglet.window.Window()
def on_draw():

OpenGL goes here. Use OpenGL as normal.

Section 180.5: Drawing Points Using Pyglet and OpenGL

import pyglet
from import * – Python® Notes for Professionals 698

win = pyglet.window.Window()
def on_draw():
glVertex2f(x, y) #x is desired distance from left side of window, y is desired distance from bottom of window

make as many vertexes as you want

To connect the points, replace GL_POINTS with GL_LINE_LOOP.

Leave a Comment