pygame错误:AttributeError:模块'pygame'没有属性'load'

时间:2019-02-10 15:17:52

标签: python pygame python-3.7

我目前正在使用python 3.7.2中的pygame进行游戏。 运行程序时出现一个奇怪的错误: 这是完整的回溯:

hello from the 1st lign of this code :D
pygame 1.9.4
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
  File "C:\Users\-------\----------\---------\WIP\newfile.py", line 69, in <module>
    Window('load')
  File "C:\Users\-------\----------\---------\WIP\newfile.py", line 52, in Window
    bg32 = pygame.load('sprites/bg32.png').convert_alpha()
AttributeError: module 'pygame' has no attribute 'load'

这真的很奇怪,因为“加载”功能是pygame的一个非常基本的导入功能... 所以这是我的代码(完整),我仍然不明白这里出了什么问题:

print('hello from the 1st lign of this code :D')
import time
spb = time.time()

import pygame
import os, sys
pygame.init()

os.environ['SDL_VIDEO_CENTERED'] = '1'
Very_Dark_Blue = ( 0, 0, 64)

barPos = (0, 0)
barSize = (400, 40)
borderColor = ( 0, 0, 0,)
max_a = 10000
a=0

screen=pygame.display.set_mode((1,1), pygame.NOFRAME)


def text(show_text, show_size, show_color, show_x, show_y):
    fontObj = pygame.font.Font('Display_Font.ttf',show_size)
    Load_text = fontObj.render(show_text,True,show_color,None)
    render_text  = Load_text.get_rect()
    render_text.center = (show_x,show_y)
    screen.blit(Load_text,render_text)
def image(name,x,y):
    screen.blit(name,(x,y))
def DrawBar(pos, size, borderC, barC, progress):
    global screen
    pygame.draw.rect(screen, borderC, (*pos, *size), 1)
    innerPos = (pos[0]+3, pos[1]+3)
    innerSize = ((size[0]-6) * progress, size[1] - 6)
    pygame.draw.rect(screen, barC, (*innerPos, *innerSize))

def Window(w):
    global screen,a,max_a,barPos,barSize,Very_Dark_Blue,borderColor
    if w == 'load':
        screen=pygame.display.set_mode((400,40), pygame.NOFRAME)
        bg32 = pygame.load('sprites/bg32.png').convert_alpha()
        while w == 'load':
            image(bg32,0,0)
            DrawBar(barPos, barSize, borderColor, Very_Dark_Blue, a/max_a)
            pygame.display.update()
            a = a + 1
            if a == max_a:
                Window('main')
    if w == 'main':
        pygame.quit
        screen=pygame.display.set_mode((1920,1080), pygame.NOFRAME)
        while w == 'main':
            image(background,0,0)
            image(title,100,0)
            pygame.display.update()

Window('load')
background = pygame.image.load('sprites/Background.png').convert_alpha()
title = pygame.image.load('sprites/Title.png').convert_alpha()

所以我希望有人会发现问题:D 感谢任何愿意帮助我的人!

1 个答案:

答案 0 :(得分:1)

正如Rabbid76在评论中所说,加载功能是image模块的一部分,因此您必须使用pygame.image.load(...)而不是pygame.load(...)