How do I unload images in Pygame?

2019-05-31 03:28发布

问题:

I am trying to rename an image currently being viewed in a PyGame window (same program), and since that isn't really a good idea, I had it rename at the end of the program. However, it still gives me the error:

WindowsError: [Error 32] The process cannot access the file because it is being
used by another process

I tried "quitting" (un-initializing) the PyGame and the display, but it still says that it cannot rename the file with the error above.

Is there a way to unload images? Is that what I need to do?

Thanks!

回答1:

Try getting a file object and using that instead, for example:

f = open('myfile.png')
pygame.image.load(f)
f.close()


标签: python pygame