找不到Pygame Modu

2024-04-19 00:50:56 发布

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

我刚开始用pygame在python中开发游戏,我有以下代码:

bif="main_background.jpg"
mif="player_head.png"

import pygame, sys
from pygame.locals import *

pygame.init()
screen=pygame.display.set_mode((640,360),0,64)

background=pygame.image.load(bif).convert()
mouse_c=pygame.image.load(mif).convert_alpha()

while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()

    screen.blit(background, (0,0))

    x,y = pygame.mouse.get_pos()
    x -= mouse_c.get_width()/2
    y -= mouse_c.get_height()/2

    screen.blir(mouse_c,(x,y))

    pygame.display.update()

我在Python中得到以下错误:

Traceback (most recent call last):
  File "C:/Users/Eier/Documents/Code Developments/pygame.py", line 4, in <module>
    import pygame, sys
  File "C:/Users/Eier/Documents/Code Developments\pygame.py", line 5, in <module>
    from pygame.locals import *
ImportError: No module named locals
>>> 

如果有人知道如何让python找到pygame,请回复。

谢谢:)


Tags: infromimporteventgetdisplaysysscreen