Pyglet,如何让ESCAPE键不关闭窗口?
我正在编写一个小示例程序,我想覆盖 ESC 关闭应用程序的默认 pyglet 行为。我有一些东西:
window = pyglet.window.Window()
@window.event
def on_key_press(symbol, modifiers):
if symbol == pyglet.window.key.ESCAPE:
pass
但这似乎不起作用。
I am writing a small sample program and I would like to override the default pyglet's behavioyr of ESC closing the app. I have something to the extent of:
window = pyglet.window.Window()
@window.event
def on_key_press(symbol, modifiers):
if symbol == pyglet.window.key.ESCAPE:
pass
but that does not seem to work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我知道这个问题很老了,但以防万一。您必须返回 pyglet.event.EVENT_HANDLED 以防止默认行为。我没有测试它,但理论上这应该有效:
I know the question is old, but just in case. You've got to return pyglet.event.EVENT_HANDLED to prevent default behaviour. I didn't test it, but in theory this should work:
对我来说也一样。这个问题很老了,但我发现您应该使用窗口处理程序机制,从而使当前事件不会进一步传播。
这是链接
Same for me. The question is old, but I've found out that you should use window handlers mechanisms, thus making the current event not to propagate further.
Here is that link
在 pyglet-users 的 Google 群组中,建议可能会使窗口过载。 Window.on_key_press(),尽管没有它的代码示例。
On the Google group for pyglet-users it is suggest could overload the window.Window.on_key_press(), although there are no code example of it.
实际上很简单,子类化 Window 并覆盖 on_key_press,如下所示:
It's simple actually, subclass Window and overide the on_key_press, like this: