python错误python 3.5 pygam

2024-04-19 14:18:21 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我想做一个游戏…而pygame似乎不适合我。我得到了这个错误

AttributeError: module 'pygame' has no attribute 'init'"

我尝试了其他所有的论坛,但都找不到帮助…我的游戏叫roll,我使用的是正确的pygame。我该怎么办?你知道吗

import pygame
pygame.init()

gamedisplay = pygame.display.set_mode((800,600))
pygame.display.set_caption('roll.io')
clock = pygame.time.Clock()

dead = False

while not dead:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            dead = True

        print(event)

    pygame.display.updat()
    clock.tick(30)

pygame.quit()
quit()

Tags: noevent游戏init错误displaypygamequit
2条回答

你试过包括

    from pygame.locals import *

我在为最新的python版本安装pygame时也遇到了一些问题,主要是因为所有的指南都是旧的或者不支持最新的python版本。 这就是我的工作原理:

首先从here下载(我为您上传了它,因为我甚至找不到我最初下载它的地方……),然后复制文件并将其粘贴到[your python folder]/scripts,然后打开cmd type cd[location of your script folder],最后键入pip3 install pygame-1.9.2a0-cp35-none-win32.whl,不要尝试将其重命名为较短的文件名,因为某些原因这行不通。你知道吗

相关问题 更多 >