I am trying to show list of selected images sequentially on a label image, but all the attempts I have skip to the last image. Please help
from tkinter import *
from tkinter.filedialog import askopenfile, askdirectory, askopenfilenames
from PIL import ImageTk, Image
def load_images(window):
global files
files = askopenfilenames(parent=window, title="Choose image(s)", filetype=[("Images", "*.Jpg")])
files = iter(files)
update_image(window, next(files))
def update_image(window, img):
image = ImageTk.PhotoImage(Image.open(img))
label_img.configure(image=image)
label_img.image = image
img = next(files)
if img:
window.after(2, update_image(window, img))
else:
return
if __name__ == "__main__":
root = Tk()
menubar = Menu(root)
file = Menu(menubar, tearoff=0)
file.add_command(label="Load image(s)", command=lambda:load_images(root))
file.add_command(label="Exit", command=root.quit)
menubar.add_cascade(label="File", menu=file)
root.config(menu=menubar)
test_image = ImageTk.PhotoImage(image=Image.open("test.jpg"))
global label_img
label_img = Label(root, image=test_image, bg="#2D2D2D")
label_img.pack(fill=X, padx=10)
root.mainloop()
And this code is throwing the following.
window.after(2, update_image(window, img))
File "......./Documents/python/v3/GUI.py", line 21, in update_image
img = next(files)
StopIteration