luyantl 发表于 2018-10-4 23:28:54

Python求助

import pygame
import 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()

luyantl 发表于 2018-10-4 23:29:34

======= 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'

luyantl 发表于 2018-10-4 23:30:16

第一楼的代码,第二楼是报错信息,照书抄的代码,不明白哪错了

1005204767 发表于 2018-10-6 17:33:01

我复制你的代码运行可以,你是不是pygame没安装好?要不重新安装pygame试试

luyantl 发表于 2018-10-7 00:10:09

1005204767 发表于 2018-10-6 17:33
我复制你的代码运行可以,你是不是pygame没安装好?要不重新安装pygame试试

找到原因了,是因为我设置了一个名为pygame的文件,产生了路径错误
页: [1]
查看完整版本: Python求助