Reputation: 41
I'm having trouble uploading an image in pygame. Here's my code.
import pygame, sys
from pygame.locals import *
def Capitals():
pygame.init()
DISPLAYSURF = pygame.display.set_mode((500, 400))
pygame.display.set_caption('Capitals')
BLACK = ( 0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
DISPLAYSURF.fill(WHITE)
DISPLAYSURF=pygame.image.load('USA.jpg').convert()
while True:
for event in pygame.event.get():
if event.type==QUIT:
pygame.quit()
sys.exit()
pygame.display.update()
The picture isn't having a problem loading on the python page, there is no "cannot open file error", but on the actual pygame window, the image isn't loading.
Upvotes: 0
Views: 592
Reputation: 101032
To display an image on the screen, you have to draw it on the display surface (using blit
). What you are doing here
DISPLAYSURF=pygame.image.load('USA.jpg').convert()
is loading the image and assign it to the DISPLAYSURF
variable.
So use this instead:
image=pygame.image.load('USA.jpg').convert() # load the image
DISPLAYSURF.blit(image, (0, 0)) # blit it to the screen
Upvotes: 2