Hint:
Looks to me like you are creating the same label over and over again.
Ene Uran
Posting Virtuoso
1,723 posts since Aug 2005
Reputation Points: 625
Solved Threads: 213
You could take each labelobject an append it to a list.
Ene Uran
Posting Virtuoso
1,723 posts since Aug 2005
Reputation Points: 625
Solved Threads: 213
Try something like this:
label = list(range(len(files)))
for k, fname in enumerate(files):
image = Image.open(filedir+"/"+fname)
##((width, height))
image.thumbnail((160, 240))
photo = ImageTk.PhotoImage(image)
label[k] = Label(image=photo)
label[k].image = image # keep a reference!
#label[k].pack() # pack when you want to display it
#print files
return ...
Ene Uran
Posting Virtuoso
1,723 posts since Aug 2005
Reputation Points: 625
Solved Threads: 213
Some ideas. First, tkinter does not display all image types. I do not think that it will display a JPG but am not sure. Convert some pictures to a gif and see it that works. Second, "file" is a reserved word and so should not be a variable name, Third, you are not iterating through the entire list of files because of the delete in the for loop. Append the names you want to keep to a second list. Also, you don't have to create a list of n elements, just append as you go along (see below). Finally, if you don't know about effbot, it is a good reference. http://effbot.org/tkinterbook/label.htm
label_list = []
for k, fname in enumerate(files):
image = Image.open(filedir+"/"+fname)
##((width, height))
image.thumbnail((160, 240))
photo = ImageTk.PhotoImage(image)
this_label = Label(root, image=photo)
this_label.pack() # pack when you want to display it
label_list.append( this_label )
picSet.mainloop()
woooee
Nearly a Posting Maven
2,454 posts since Dec 2006
Reputation Points: 777
Solved Threads: 714
vegaseat
DaniWeb's Hypocrite
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417