Fair enough, keep in mind though that there are different ways of writing code, these are just a few of examples. In the Pyglet example the update() function is the main loop, its called continuously by schedule_interval(). Other functions like on_key_press() wait for input and trigger events as needed. Here's a different example:
import pyglet
from pyglet.window import key
#main class
class Example(pyglet.window.Window):
def __init__(self):
super(Example, self).__init__(640, 480, caption="Example")
#load a sound
self.sound = pyglet.media.load('example.wav',streaming=False)
#load an image
self.picture = pyglet.image.load('example.png')
#run our update function continuously
pyglet.clock.schedule_interval(self.update, .01)
#primary update loop
def update(self,dt):
#draw screen
self.draw()
#draw to the screen
def draw(self):
self.clear()
self.picture.blit(0,0)
#capture key presses
def on_key_press(self,symbol,modifiers):
#if space is pressed, play sound
if symbol == key.SPACE:
self.sound.play()
#if escape pressed, quit
if symbol == key.ESCAPE:
self.close()
window = Example()
pyglet.app.run()
In the end it really depends on what you have in mind, you should pick and choose which library you want to use based on your current needs. If you feel Pygame is an easier fit, then go for it and see how it goes.
-
BrushTone v1.3.3: Accessible Paint Tool
-
AudiMesh3D v1.0.0: Accessible 3D Model Viewer