Hi gurkesaft,
The style you show should work just fine, there's nothing wrong with
it.
Personally I prefer to think of that application has-a window, and it
has-a keyboard handler
class KeyHandler(object):
def on_key_press(self, key, modifiers):
...
def on_key_release(self, key, modifiers):
...
class MyApplication(object):
def __init__(self):
self.win = Window(...)
self.keyhandler = KeyHandler()
self.win.push_handlers(self.keyhandler)
This idea can be extended to give your application more than one
keyboard handler, adding and removing them by calling win.push_handlers
() or win.remove_handlers() as needed. (eg. one handler that knows
about on-screen menus, that is pushed whenever a menu is on screen.
Another handler which knows how to move the player around, pushed
whenever the player's character is moveable)
But it's just a matter of personal preference. Your way should also be
just fine.