# Python Pyglet Module

Pyglet is a cross-platform windowing and multimedia library for Python. It is intended for developing games and other visually rich applications. It has no external dependencies or installation requirements.

## Installation

```bash
pip install pyglet
```

## Basic Window

```python
import pyglet

window = pyglet.window.Window(width=800, height=600, caption="Hello Pyglet")

@window.event
def on_draw():
    window.clear()

pyglet.app.run()
```

## Displaying Text

```python
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()
```

## Handling Input

```python
from pyglet.window import key

@window.event
def on_key_press(symbol, modifiers):
    if symbol == key.A:
        print('The "A" key was pressed.')
    elif symbol == key.LEFT:
        print('The left arrow key was pressed.')
```

## Working with Images

```python
image = pyglet.image.load('kitten.png')

@window.event
def on_draw():
    window.clear()
    image.blit(0, 0)
```

## Playing Sound

Pyglet can play WAV and other audio formats.

```python
music = pyglet.resource.media('music.mp3')
music.play()
```

[[programming/python/python]]