Python Tkinter PhotoImage not displaying gif properly

Question:

I’m attempting to put an image into one of my Frames for my Python Tkinter window, but all that keeps showing up is a white box the size of the image. I’m using a GIF image and the Tkinter PhotoImage.

tkinter.Tk.__init__(self,master)
self.title("Apex Companion")
self.resizable(width=False, height=False)
self.geometry("250x400")
self.overrideredirect(True)
self.config(bg="#393939")
#Tob Bar Frame
tb = tkinter.Frame(self,height=20,width=250,bg="#232323")
tb.pack_propagate(False)
#Top Bar Text
tb_text = tkinter.Label(tb, text="Apex Companion",bg="#232323",fg="#737373")
#Top Bar Close
tb_close = tkinter.Button(tb, height=2, width=3,
                          text="✕", bg="#232323", fg="#ffffff",
                          activebackground="#c94343",activeforeground="#ffffff",
                          command=self.destroy, bd=0)
#Top Bar Minimize
tb_min = tkinter.Button(tb, height=2, width=2,
                        text="—", bg="#232323",fg="#ffffff",
                        bd=0)
#Top Bar Logo
tb_img = tkinter.PhotoImage(file="logo_apc.gif")
tb_logo = tkinter.Label(tb,image=tb_img)

tb.pack()
tb_close.pack(side=tkinter.RIGHT)
tb_min.pack(side=tkinter.RIGHT)
tb_logo.pack(side=tkinter.LEFT)
tb_text.pack()
Asked By: Maverick Davidson

||

Answers:

It can be bug which removes PhotoImage from memory when you assign it to local variable.

Try to assign it to class variable self.tb.img = tkinter.PhotoImage(...)

More on the botton of the page: effbot.org/tkinterbook/photoimage.htm

Answered By: furas
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.