After some deliberation, I found that the image displays correctly when saved in a GUI variable, i.e. using self
self.gif1 = PhotoImage(file='1.gif') self.canvas.create_image(0, 0, image=self.gif1, anchor=NW)
I have no idea why, but it works, but to name a variable is just gif1 (or any other name) without self , no. Tested both in code and in a minimal example.
Update: As @Bryan pointed out, the garbage collector provides an instance of PhotoImage when __init__ ends. You should keep a reference to an instance that is outside the scope of the constructor, for example. using self or global . Given this problem, it would be better to create a dict by saving images using map names as keys.
source share