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.

Recommended Answers

Here one example with tk.Tk class of vegaseat:
[CODE]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()
[/CODE]

Same but inherit from …

Jump to Post

All 4 Replies

Re: Images not displaying in tkinter 80 80

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

Re: Images not displaying in tkinter 80 80

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()
Re: Images not displaying in tkinter 80 80

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
Re: Images not displaying in tkinter 80 80

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 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.