r/pythonhelp • u/northernbloke • Mar 17 '22
Trying to output images in a grid
Hi all, I'm trying to output some images from an array of file paths to a grid with tkinter and PIL.
The code recreates the same label box repositions it and changes the image on each loop. How do i create a new label each loop?
EDIT: IF anyone has a more elegant solution, please let me know!
#files is a array of local image address i.e d:\photos\dirname\photoname.jpg
for file in files:
image_data = file
loaded_img = Image.open(image_data)
resized_img = loaded_img.resize(TARGET_SIZE)
photo_img = ImageTk.PhotoImage(resized_img)
make_label(root, x, y, 200, 166, photo_img)
x=x+200
if(x > 1000):
y = y + 166
x = 0
if(y > 320):
break
2
Upvotes