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.

What type self has? Maybe you should use self.grid?

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()

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()
commented: Best solution +3

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.