Most games will need to load and display images on the screen. In this example we'll load an image from the application's directory and display it within the window:
import pyglet window = pyglet.window.Window() image = pyglet.resource.image('kitten.jpg') @window.event def on_draw(): window.clear() image.blit(0, 0) pyglet.app.run()
We used the pyglet.resource.image function to load the image, which automatically locates the file relative to the source file (rather than the working directory). To load an image not bundled with the application (for example, specified on the command line, you would use pyglet.image.load).
The AbstractImage.blit method draws the image. The arguments (0, 0) tell pyglet to draw the image at pixel coordinates 0, 0 in the window (the lower-left corner).
The complete code for this example is located in examples/programming_guide/image_viewer.py.