0

pygame freezes in this loop at around cycle 150. The loop continues, but pygame stops updating here's my code:

import pygame
from cv2 import imread # the only one needed! (to get image size) could of used pygame though... 

image = imread("frame0.jpg") # get the first frame to get size of framed video
h, w, channels = image.shape
screen = pygame.display.set_mode((w,h)) # define the surface
c = pygame.time.Clock()
for i in range(0,4099): # i know this is VERY inefficent... start frame - end frame
    im = pygame.image.load("./frame%d.jpg" % i) #load frame
    screen.blit(im, [0, 0]) # put the image on the surface
    pygame.display.update() # update time! where you've been?
    screen.fill((0,0,0)) # delete canvas after update the events can be below due to the update occuring next cycle
    print(i) # debug
    del im # delete image variable (not necessary)
    c.tick(30) # tick the clock! tick tock!!
print("done!")

so what this code is supposed to do is play a series of images in a folder. but pygame freezes and the loop continues. and this is a for loop. is it my update method? is there a way to fix this?

also, if i lower the frame rate to something like 10, the same thing happens at the same frame. is there a limit to pygame.display.update()?

The Matt
  • 1,423
  • 1
  • 12
  • 22
thomask
  • 1
  • 1
  • 1
    You have to call one of the [event](http://www.pygame.org/docs/ref/event.html) functions, for example `pygame.event.pump`, in your for loop to prevent this. – skrx Jan 27 '18 at 01:11
  • oh thx skrx i did not look hard enough – thomask Jan 27 '18 at 01:41

0 Answers0