There is no on_draw
or on_mouse_press
function defined for pyglet.window.Window
, so you cannot call them. In the base class, these only exist as registered event types, which means that when the window receives one of them through dispatch_event()
, it will first check its event stack for a handler, then its own attributes for a function with a matching name. If there is no match in either place, the event is ignored. This is what allows you to define a handler directly as you did in your code, or by using a decorator outside the class to push a handler onto the stack (or both).
The EventLoop
does dispatch an on_draw
event to each window during every iteration, but flip()
is called separately.
Source:
class EventLoop(event.EventDispatcher):
# ...
def idle(self):
# ...
# Redraw all windows
for window in app.windows:
if redraw_all or (window._legacy_invalid and window.invalid):
window.switch_to()
window.dispatch_event('on_draw')
window.flip()
window._legacy_invalid = False