I'm having an issue displaying images in tkinter, I've tried the methods suggested by effbot and a couple other sources to no avail. Here are a couple ways I've tried so far:

gmail=PhotoImage('gmail.gif')
        self.glab=Label(self,image='gmail.gif')
        self.glab.image=gmail
        self.glab.grid(row=3,column=4)

        gmail=PhotoImage('gmail.gif')
        self.glab=Label(self,image=gmail)
        self.glab.image=gmail
        self.glab.grid(row=3,column=4)

        self.glabim=PhotoImage('gmail.gif')
        self.glab=Label(self,image=self.glabim)
        self.glab.grid(row=3,column=4)


        gmail=PhotoImage('gmail.gif')
        self.lab=Label(self,image=gmail)
        self.lab.image=gmail
        self.lab.pack()

the last one actually froze the program completely, it wouldn't run. I'm sure the images are in the correct directory.

Edited 5 Years Ago by pyguy62: n/a

The Tkinter keyword is "image" not "self.image"; see the example here. Also, a label is usually in a frame or some other container. Finally, you can not mix grid() and pack() so choose one or the other.

gmail=PhotoImage(file='gmail.gif')
self.lab=Label(image=gmail)
self.lab.photo=gmail
self.lab.pack()

Edited 5 Years Ago by woooee: n/a

Here one example with tk.Tk class of vegaseat:

try:
    import Tkinter as tk
except ImportError:
    import tkinter as tk
    
class MyApp(tk.Tk):
    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)
        self.root = tk.Frame()
        self.root.pack()
        
        self.image = tk.PhotoImage(file='gmail.gif')
        self.gmail = tk.Label(self.root, image=self.image)
        self.gmail.pack()
        
app = MyApp()
app.mainloop()

Same but inherit from tk.Frame:

try:
    import Tkinter as tk
except ImportError:
    import tkinter as tk
    

class MyApp(tk.Frame):
    def __init__(self, *args, **kwargs):
        tk.Frame.__init__(self, *args, **kwargs)
        self.pack()

        self.image = tk.PhotoImage(file='gmail.gif')
        self.gmail = tk.Label(self, image=self.image)
        self.gmail.pack()
        
root= tk.Tk()
app = MyApp()
app.mainloop()

Edited 5 Years Ago by pyTony: Better variable name, pack order

Comments
Best solution
Attachments gmail.gif 14.36 KB

It looks like my issue was the image, which is strange, but I'm going to just have to figure that one out I guess

This question has already been answered. Start a new discussion instead.