python 3.x - Image doesn't load in pygame -
i'm having trouble uploading image in pygame. here's code.
import pygame, sys 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: event in pygame.event.get(): if event.type==quit: pygame.quit() sys.exit() pygame.display.update()
the picture isn't having problem loading on python page, there no "cannot open file error", on actual pygame window, image isn't loading.
to display image on screen, have draw on display surface (using blit
). doing here
displaysurf=pygame.image.load('usa.jpg').convert()
is loading image , assign displaysurf
variable.
so use instead:
image=pygame.image.load('usa.jpg').convert() # load image displaysurf.blit(image, (0, 0)) # blit screen
Comments
Post a Comment