我对Python非常陌生,我的一张图像不会绘制到屏幕上

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

我试图在屏幕上绘制图像,但不断出现错误。错误一直显示“视频系统未初始化”。我是Python新手,有人可以帮忙吗?

import pygame
import os
#game window
WIN = pygame.display.set_mode((1000, 800))
NAME = pygame.display.set_caption("Space War!")
#FPS limit
FPS = (60)

#image i am trying to draw onto screen
SPACE_BACKGROUND = pygame.image.load(os.path.join('space_background.png'))

pygame.init()
#allows pygame to quit
def main():
    clock = pygame.time.Clock()
    run = True
    while run:
        clock.tick(FPS)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:

                pygame.quit()
        #updates images 
        pygame.display.update()
#calling def main(): function
if __name__ == "__main__":
    main()
python image pygame background operating-system
1个回答
1
投票

做:

def main():
    clock = pygame.time.Clock()
    run = True
    FPS = 60
    while run:
        clock.tick(FPS)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:

                pygame.quit()
        #updates images 
        WIN.blit(SPACE_BACKGROUND, (0, 0)) #you FORGOT this part
        pygame.display.update()
© www.soinside.com 2019 - 2024. All rights reserved.