As most of us know in tkinter in order to properly display an image it must be assigned to a variable, however what if you don't know that amount of images that are going to be necessary? i.e. A friend list, how would one display the friends pictures?

Does the friend list bring anything to mind?

It does, but I'm stuck in a pattern of thinking I can't get out of with the use of it, here's what I've been trying:

self.box=Listbox(self)
        self.box.pack()
        list1=['icon_man.gif','group_icon.gif']
        for img in list1:
            imag=PhotoImage(file=img)
            self.box.insert(END,imag)

This just puts the word (pyimage"whatever number") in the box, which makes sense "unfortunately" any alternative ideas?


And to make sure that it wasn't just the listbox being an issue

def create_widget(self):
        self.lab=Label(self)
        self.lab.pack()
        list1=['icon_man.gif','group_icon.gif']
        for file in list1:
            word=PhotoImage(file=file)
            self.lab['image']=word

I do not know details by heart, but for this part I would think that code would go more like:

self.box=Listbox(self)
        self.box.pack()
        list1=[PhotoImage(file=img) for img in 'icon_man.gif','group_icon.gif']
        for imag in list1:
            self.box.insert(END,imag)

Maybe even with generator expression:

self.box=Listbox(self)
        self.box.pack()
        for imag in (PhotoImage(file=img) for img in 'icon_man.gif','group_icon.gif'):
            self.box.insert(END,imag)

It seems the best way, at least to me, is to have a set amount labels with images on the page, and have something like a next button that will reassign the image value of the label.

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.