【问题标题】:pygame GUI python3.6pygame GUI python3.6
【发布时间】:2017-07-29 14:52:15
【问题描述】:

我已经为此苦苦挣扎了一段时间,想问一下。我从 https://github.com/ddorn/GUI 下载了 pygame GUI。基本上问题是当您尝试使用它时会发生此错误:

if e.key == K_RIGHT:
AttributeError: 'Event' object has no attribute 'key'

我尝试将e.key 更改为o.key,但没有任何反应。弹出同样的错误。我试图联系作者,但失败了。请帮忙。

【问题讨论】:

  • 什么是e?你的代码片段的上下文是什么?
  • e.key 在 for 循环中,您基本上是将 e 设置为 pygame.event.get()。

标签: python user-interface pygame


【解决方案1】:

Pygame 事件非常简单。以这种方式使用它们:

for e in pygame.event.get():
    if e.type == pygame.KEYDOWN:
        if e.key == pygame.K_RIGHT:
            print("Right Arrow Key")

注意不要忘记pygame.init(),运行后pygame.quit()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-20
    • 2012-02-06
    • 2016-03-24
    • 1970-01-01
    • 2019-12-27
    • 1970-01-01
    相关资源
    最近更新 更多