In login
, photo
is a local variable. When the login
function ends, the local variable photo
may be garbage collected. Fredrik Lundh explains the problem this way:
When Python’s garbage collector discards the Tkinter object, Tkinter tells Tk to release the image. But since the image is in use by a widget, Tk doesn’t destroy it. Not completely. It just blanks the image, making it completely transparent…
The solution is to keep a reference to the PhotoImage. Since you aren't using classes, the easiest way to keep a reference is to make photo
a global variable:
def login():
global photo
...
lblpicture.configure(image=photo)
This will also allow the content-large-white.gif
to be the default image if neither the if-condition
or the elif-condition
is True; as it stands, Python raises a UnboundLocalError
if it reaches that case.