Onecore

  • Home
  • About
  • Advertise
  • Archives
  • Privacy Policy
  • Contact

Pyglet Python Programming on Ubuntu Linux

software templates

I am going to cover pyglet graphics library for ubuntu users. You can use any other linux distro as per your choice. The instructions will slightly vary, you can take help from respective distro forums and IRC if you need.

Installation

For Ubuntu users, pyglet can be downloaded from software center. Just type pyglet in the search bar and you will be able to download the version specific to your repository. You can also manually download the tarball and build pyglet on your own.

Other methods like building from setup.py and runtime eggs is possible as well. Setup.py method for the pyglet is also easy if you know how to use terminal.

Check your pyglet installation by opening terminal and then going into python shell. Just type import pyglet, that will either show error if it is not installed or if it is installed blank prompt will be returned.

Hello Pyglet

Let’s start with blank window application with pyglet and build from there.

import pyglet
window = pyglet.window.Window()
label = pyglet.text.Label('Hello, world',
                          font_name='Arial',
                          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()

In the first line we are importing pyglet lib. In second line we are adding the label() method with parameters modifying the label. In third line we are clearing the window and drawing the label. And in the last line we are running the window.

As we are using this lib for the graphics, let’s see how we can use this lib for showing images on screen.

Add the following line in the third line.

label = pyglet.text.Label('Yummy Cheese',
                          font_name='Arial',
                          font_size=18, color=(255, 255, 255,255),
                          x=window.width//6, y=window.height//6,
                          anchor_x='center', anchor_y='center')
image = pyglet.resource.image('cheese.jpeg')

Replace the cheese.gif with any other image name you have on your hard drive. I used cheese.gif so that I can show this demo quickly.

That’s it for simple starting tutorial in pyglet programming. In future tutorials we will see how to manage events, keyboard control and mouse gestures. So that you can build games or a graphics demo using python for your requirement. Hope this helps and let me know If you have any further questions via twitter.

software templates

Featured Articles

  • Sample Test Cases for Calendar App
  • Sample Test Cases for Dialog Box
  • Test Cases for Amazon Login Screen Page
  • Sample Test Cases for Online Editor
  • Sample Test Cases for Online Book Shopping

WPForms

ENDORSEMENT DISCLOSURE: In order for us to support our website activities, we may receive monetary compensation or other types of remuneration for our endorsement, recommendation, testimonial and/or link to any products or services from this website.

Copyright © 2025 . This website uses cookies to ensure you get the best experience on our website.