Tkinter PIL image not displaying inside of a function

It does not work inside function, since tkimg is garbage collected after function finishes. You need to bind your images into variables that wont be garbage collected. For example to global variables, or instance variables in a class, rather than local variables.

To make tkimg be able to write to the global tkimg use global tkimg in the function.

Leave a Comment