| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2503 人关注过本帖
标题:求助:AttributeError: 'Event' object has no attribute 'key'
只看楼主 加入收藏
shelly411430
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2020-6-3
收藏
 问题点数:0 回复次数:1 
求助:AttributeError: 'Event' object has no attribute 'key'
用python3.0和pycharm编程,代码如下:

import sys

import pygame

def check_event(ship):
    """响应按键和鼠标事件"""
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_RIGHT:
                ship.moving_right = True
            elif event.key == pygame.K_LEFT:
                ship.moving_left = True
        elif event.key == pygame.KEYUP:
            if event.key == pygame.K_RIGHT:
                ship.moving_right = False
            elif event.key == pygame.K_LEFT:
                ship.moving_left = False


def update_screen(ai_settings, screen, ship):
    """更新屏幕上的图像,并切换到新屏幕"""
    screen.fill(ai_settings.bg_color)
    ship.blitme()

    # 让最近绘制的屏幕可见
    pygame.display.flip()
搜索更多相关主题的帖子: Event key 屏幕 pygame ship 
2020-06-03 15:22
shelly411430
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2020-6-3
收藏
得分:0 
发现错误,elif event.key == pygame.KEYUP: 应为 elif event.type == pygame.KEYUP:
2020-06-03 15:45
快速回复:求助:AttributeError: 'Event' object has no attribute 'key'
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019612 second(s), 11 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved