Python求助
import pygameimport sys
def run_game():
#初使化游戏并创建一个屏幕对象
pygame.init()
screen=pygame.display.set_mode((1200,800))#这里用了双括号?
pygame.display.set_caption("外星人入侵游戏alien invasion")
#开始游戏的主循环
while True:
#监视键盘和鼠标事件
for event in pygame.event.get():
if event.type==pygame.QUIT:
sys.exit()
#让最近绘制的屏幕可见
pygame.display.flip()
run_game()
======= RESTART: E:/study163/Python@20180819/alien_invasion/pygame.py =======
Traceback (most recent call last):
File "E:/study163/Python@20180819/alien_invasion/pygame.py", line 1, in <module>
import pygame
File "E:/study163/Python@20180819/alien_invasion\pygame.py", line 21, in <module>
run_game()
File "E:/study163/Python@20180819/alien_invasion\pygame.py", line 6, in run_game
pygame.init()
AttributeError: module 'pygame' has no attribute 'init' 第一楼的代码,第二楼是报错信息,照书抄的代码,不明白哪错了 我复制你的代码运行可以,你是不是pygame没安装好?要不重新安装pygame试试 1005204767 发表于 2018-10-6 17:33
我复制你的代码运行可以,你是不是pygame没安装好?要不重新安装pygame试试
找到原因了,是因为我设置了一个名为pygame的文件,产生了路径错误
页:
[1]