How do I unload images in Pygame?

为君一笑 提交于 2019-12-23 03:02:07

问题


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()


来源:https://stackoverflow.com/questions/30633320/how-do-i-unload-images-in-pygame

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!