Unable to load image using pygame

Viewed 27

I am unable to get the window when I run the program. I don't know what's wrong with the code. Can anyone please help me out with it?

Here's the program

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()
1 Answers

It is a matter of Indentation:

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()
Related