View images in "Gallery" with Python (Tkinter)

Asked

Viewed 13 times

0

Hello, the idea is to select all images from a directory (folder), it would display all these thumbnail images in a WINDOW via TKINTER (Python).

I was able to locate all the directories of the images with WHILE, as in the code below, but I can’t make them all display automatically.

Would you have any library or native function to create this "gallery" of images?

from tkinter import *
from typing import Sized
from PIL import *
import os
import cv2

class Window(Frame):
    

    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.master = master
        self.pack(fill=BOTH, expand=1)
        
        load = Image.open("temporario/page0.png")
        load.thumbnail((350,350))
        render = ImageTk.PhotoImage(load)
        
        img = Label(self, image=render)
        img.image = render
        img.place(x=50, y=50) 


        files = []
        pasta = 'temporario'
        for (diretorio, subpastas, arquivos) in os.walk(pasta):
            files.extend(arquivos)
        #print(pasta + '/' + files[2])
        
        
        i = 0
        while i <= 2:
            
            ronaldo = 0
            dirImg = pasta + '/' + files[i]
            loading = Image.open(dirImg)
            loading.thumbnail((350,350))
            renderiza = ImageTk.PhotoImage(loading)            
            
            i = i + 1
            print(dirImg)
            imagemA = Label(self, image=renderiza)
            imagemA.image = renderiza
            imagemA.place(x=350, y=50)

            
root = Tk()
app = Window(root)
root.wm_title("Tkinter window")
root.geometry("800x500")
root.mainloop()

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.