Pygame的错误:AttributeError的:模块“pygame的”有没有属性“负荷”

问题描述 投票:0回答:1

我目前正在与pygame的游戏,在Python 3.7.2。我有一个奇怪的错误,当我运行我的程序:这是一个完整回溯:

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感谢谁将会尽力帮助我!

python pygame python-3.7
1个回答
1
投票

作为Rabbid76在评论已经说了,负载的功能是image模块的一部分,所以你必须改用pygame.image.load(...)pygame.load(...)

© www.soinside.com 2019 - 2024. All rights reserved.