繁体   English   中英

无法使用 pygame 加载图像

[英]Unable to load image using pygame

运行程序时,我无法获得 window。 我不知道代码有什么问题。 谁能帮我解决这个问题?

这是程序

import pygame



def game():

    pygame.init()
    
    size = (500, 500)
    screen = pygame.display.set_mode(size)
    pygame.display.set_caption("PygameDemo")
    
    
    #adding background
    screen.fill((78,56,78))
    
    #load resources
    block = pygame.image.load("resources\pythonres.jpg").convert()
    screen.blit(block,(0, 0))
    
    running = True
    
    while running:
        pygame.display.flip()
        
    if __name__ == "__main__":
        game()

这是一个缩进的问题:

import pygame

def game():

    pygame.init()
    
    size = (500, 500)
    screen = pygame.display.set_mode(size)
    pygame.display.set_caption("PygameDemo")
    
    
    #adding background
    screen.fill((78,56,78))
    
    #load resources
    block = pygame.image.load("resources\pythonres.jpg").convert()
    screen.blit(block,(0, 0))
    
    running = True
    
    while running:
        pygame.display.flip()
       
# INDENTATION
#<--| 
if __name__ == "__main__":
    game()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM