Pyglet
Hello World in Pyglet
Section titled “Hello World in Pyglet”import pygletwindow = 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.eventdef on_draw(): window.clear() label.draw()pyglet.app.run()Installation of Pyglet
Section titled “Installation of Pyglet”Install Python, go into the command line and type:
Python 2:
pip install pygletPython 3:
pip3 install pygletPlaying Sound in Pyglet
Section titled “Playing Sound in Pyglet”sound = pyglet.media.load(sound.wav)sound.play()Using Pyglet for OpenGL
Section titled “Using Pyglet for OpenGL”import pygletfrom pyglet.gl import *
win = pyglet.window.Window()
@win.event()def on_draw(): #OpenGL goes here. Use OpenGL as normal.
pyglet.app.run()Drawing Points Using Pyglet and OpenGL
Section titled “Drawing Points Using Pyglet and OpenGL”import pygletfrom pyglet.gl import *
win = pyglet.window.Window()glClear(GL_COLOR_BUFFER_BIT)
@win.eventdef on_draw(): glBegin(GL_POINTS) 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 glEndTo connect the points, replace GL_POINTS with GL_LINE_LOOP.