Why does Tkinter image not show up if created in a function?

The variable photo is a local variable which gets garbage collected after the class is instantiated. Save a reference to the photo, for example:

self.photo = tkinter.PhotoImage(...)

If you do a Google search on “tkinter image doesn’t display”, the first result is this:

Why do my Tkinter images not appear? (The FAQ answer is currently not outdated)

Leave a Comment