Pyget backend error with "on_key_press"

11 views
Skip to first unread message

Mike Lawrence

unread,
Feb 7, 2018, 10:32:53 AM2/7/18
to vi...@googlegroups.com
I just switched from SDL2 to pyglet as my backend, and have the code:

    class myCanvas(vispyApp.Canvas):
        ... #init and other stuff here
        def on_key_press( self , event ):
            if event.key.name=='q': 
                #do stuff


which worked fine using SDL2 but now that I'm using pyglet I'm getting the error:

    AttributeError: 'NoneType' object has no attribute 'name'

Any ideas how to fix this?


--
Mike Lawrence
Graduate Student
Department of Psychology & Neuroscience
Dalhousie University

~ Certainty is (possibly) folly ~


David Hoese

unread,
Feb 8, 2018, 8:53:47 AM2/8/18
to vispy
Hi Mike,

There shouldn't be a difference between backends for this. Could you try running `print(type(event.key))` in the `on_key_press` method and let me know what it says? FYI you should be able to do `event.key == 'q'`. The `event.key` property should be of the class `Key` (https://github.com/vispy/vispy/blob/acc4c4b24ff4e628253641df887a6e58fbd24a8e/vispy/util/keys.py#L20). Also what version of vispy are you running?

Dave
Reply all
Reply to author
Forward
0 new messages