I’ve just started playing around with pyglet.
In the first demo, I ran accross code like this:
window = pyglet.window.Window()
@window.event
def on_draw():
window.clear()
label.draw()
I understand that this registers an event handler, but I don’t understand how.
How could this be rewritten without the ‘@’ syntax?
It’s called an “event decorator.” Yes, you could just write
window.on_draw = on_draw
after the “def on_draw()” definition, without using the decorator; but then if the window already had an on_draw, it would be overwritten. The decorator will “chain” multiple event handlers together.