首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Pygame错误: AttributeError:模块'pygame‘没有属性'load’

Pygame错误: AttributeError:模块'pygame‘没有属性'load’
EN

Stack Overflow用户
提问于 2019-02-10 23:17:52
回答 1查看 2.1K关注 0票数 2

我目前正在开发一个python 3.7.2版本的pygame游戏。当我运行我的程序时,我得到一个奇怪的错误:这是完整的回溯:

代码语言:javascript
复制
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'

这真的很奇怪,因为“load”函数是pygame的一个非常基本和重要的函数……这是我的代码(完整),我仍然不明白这里出了什么问题:

代码语言:javascript
复制
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感谢任何想要帮助我的人!

EN

回答 1

Stack Overflow用户

发布于 2019-02-11 17:13:48

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54617843

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档