0

i am currently receiving images stored in database from their url after retrieving them and storing them in a file i need to show them on an GUI with python while the code is running (at the last image they should repeat) i used tkinter library but i am facing a problem that the GUI shows only the last image here is the code:

def resize_image(event):
    new_width = event.width
    new_height = event.height
    image = copy_of_image.resize((new_width, new_height))
    photo = ImageTk.PhotoImage(image)
    label.config(image = photo)
    label.image = photo

    for images in os.listdir(r"C:\Users\Ali\Desktop\imgs"):
      im = Image.open(images)
      copy_of_image = im.copy()
      photo = ImageTk.PhotoImage(im)
      label = ttk.Label(root, image = photo)
      label.bind('<Configure>', resize_image)
      label.pack(fill=BOTH, expand = YES)
    root.mainloop()

any suggestions for this problem please

1 Answers1

0

First, the program is showing the last image because it runs the loop until the last image and there is not any other instruction to stop at any given time. So the user cant select to continue. Maybe the iterations are going so fast you can see them.

I think what you are trying to do may required a little more robust infrastructure that having the pictures in a file. If you want to have a dynamic selector for a big number number of images you could do:

  1. What you propose, saving each image path on a table and when the user press or command "next image" trigger a event to bring the next image by its path (you should not bring all images up to the program running memory at the same time).
  2. Connecting directly to the database and linking the users options to the images or images url.

By seeing you function, you should call that function after building up the table with the path for the images or with your current code trying to use the time module to wait between the iterations of the loop with:

import time
seconds = 4

for i in x:
    time.time(seconds)