I started learning Pygame today and tried out this code but the image won't load and it shows no error, even tried changing the dimensions of the window and the position of the image, nothing seems to be working.
import pygame, sys
clock = pygame.time.Clock()
from pygame.locals import *
pygame.init() #iniiates pygame
pygame.display.set_caption('My Program Window')
WINDOW_SIZE = (400,400)
screen = pygame.display.set_mode(WINDOW_SIZE,0,32) #initiate the window
player_image = pygame.image.load('player.png')
moving_right = False
moving_left = False
player_location = [50,50]
while True:
screen.blit(player_image, player_location)
if moving_right == True:
player_location[0] += 4
if moving_left == True:
player_location[0] -= 4
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
if event.key == K_RIGHT:
moving_right = True
if event.key == K_LEFT:
moving_left = True
if event.type == KEYUP:
if event.key == K_RIGHT:
moving_right = False
if event.key == K_LEFT:
moving_left = False
pygame.display.update()
clock.tick(60)
[Edit]:
Solved the problem by reinstalling Pygame by following this thread: Problems getting pygame to show anything but a blank screen on Macos Mojave