Issue
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()
Solution
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 (on WaybackMachine)
Answered By - furas
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.