Python Notes and Examples
← prev | next →     Top-level ToC     /pyglet.html     (printable version)

Pyglet is a modern toolkit for making games in Python using OpenGL.

1 Install

$ . path/to/some-env/bin/activate
$ pip install future  # Why is this necessary?
$ pip install --upgrade https://bitbucket.org/pyglet/pyglet/get/tip.zip
$ cd path/to/my-pyglet-proj

Check the version you’ve installed:

$ python
>>> import pyglet
>>> pyglet.version
'1.3.0rc1'

2 Hello World

The quickstart in the Pyglet latest docs provides a hello-world program:

#!/usr/bin/env python3

import pyglet

window = pyglet.window.Window()

label = pyglet.text.Label(
    'Hello, world',
    font_name = 'Times New Roman',
    font_size = 36,
    x = window.width // 2,
    y = window.height // 2,
    anchor_x = 'center',
    anchor_y = 'center',
)

@window.event
def on_draw():
    window.clear()
    label.draw()

pyglet.app.run()