0

Currently I'm using

def load(load_list, path_to_animation_folder):
        for frame in os.listdir(path_to_animation_folder):
            full_path = os.path.join(path_to_animation_folder, frame)
            loaded_image = ImageTk.PhotoImage(Image.open(full_path))
            load_list.append(loaded_image)

It's a rather slow approach. I have a lot of sh*t to load. And it takes 2 minutes to launch the program currently, which is unacceptable, I'll need to definitely find another way.

So guys, help me out here.

Aleksas
  • 66
  • 8
  • 1
    well `tkinter` is pretty slow on its own, you could try using `.after` "loops" but that will likely not help much, you could put this thing in its own thread with the risk of crashing `tkinter` without errors but then you at least get to load the images without stopping the gui from opening. also reducing the size of the images may help and btw the `Image.open` part is pretty fast compared to converting it to a `tk.PhotoImage`, you could try doing something with `opencv` library which is faster because it uses a lot of c and then combine it with your `tkinter` gui – Matiiss Nov 28 '21 at 07:31
  • Already made it into a multithreading process, so now everything's loading in the background while the application is started. Now your idea of opencv is brilliant, however how can I make it compatible with tkinter? Are you saying I don't need to use tk.PhotoImage specifically? Appreciate the help btw – Aleksas Nov 28 '21 at 07:59
  • Holy crap, doing some experiments with cv2, it's loading stuff into memory like 1000x times faster, and no lag! It loaded something in 14 seconds that took 150 seconds previously with lag. However, I'm having problems with transparency, it's just black background, but thank you for pointing me into the right direction dude – Aleksas Nov 28 '21 at 08:09
  • well, I have almost no experience with `opencv` and definitely have no idea how to integrate it with `tkinter` but glad that it helps you, you may need to ask another question, if you need, about that part – Matiiss Nov 28 '21 at 16:37
  • @Aleksas I think you have the same problem with transparency and slow loading than me. I found a workaround that helps in some cases. Can you post example pics? https://stackoverflow.com/questions/70986295/python-imagetk-photoimage-slow-loading-of-png-with-alphachannel – andsa Feb 22 '22 at 08:00

0 Answers0