Skip to content Skip to sidebar Skip to footer

My Button In Tkinter Is Not Showing The Image

this code is just an example code: import tkinter as tk root = tk.Tk() photoImageObj = tk.PhotoImage(file='signout.png') lab = tk.Label(root, image=photoImageObj).pack() photoImage

Solution 1:

When an image is inside a function you have to keep reference to the image or it will be garbage collected by python. With the code provided its hard to say, but just try something like:

signout_button = Button(stem,image=photoImageObj)
signout_button.pack() #so that signout_button is not None
signout_button.image=photoImageObj #keeping a reference

Alternatively, you could also say global photoImageObj on top of function, but its not recommended to use global. This question should be marked as a duplicate and closed, but just in-case you dont understand what to do in your "specific case", here is the answer.

Post a Comment for "My Button In Tkinter Is Not Showing The Image"