初学python,运行pygame示例出错
cejay 2010-05-10 10:11:50 Python安装的是Python 3.1,pygame安装的是pygame-1.9.1.win32-py3.1.msi。不用pygame直接写Python脚本正常,但是pygame的示例就是不行,提示:
Traceback (most recent call last):
File "G:\python\pygame.py", line 1, in <module>
import sys,pygame,time
File "G:\python\pygame.py", line 2, in <module>
pygame.init()
AttributeError: 'module' object has no attribute 'init'
代码:
import sys,pygame,time
pygame.init()
size = width, height = 320, 240
speed = [2, 2]
black = 0, 0, 0
screen = pygame.display.set_mode(size)
ball = pygame.image.load("ball.gif")
ballrect = ball.get_rect()
running = 1
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = 0
ballrect = ballrect.move(speed)
if ballrect.left < 0 or ballrect.right > width:
speed[0] = -speed[0]
if ballrect.top < 0 or ballrect.bottom > height:
speed[1] = -speed[1]
screen.fill(black)
screen.blit(ball, ballrect)
pygame.display.flip()
time.sleep(0.03)
pygame.quit()
是不是pygame-1.9.1中没有init()了,去搜索引擎也没找到答案,求解