Skip to content

Instantly share code, notes, and snippets.

@endolith
Last active July 1, 2021 16:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save endolith/50e50ad6b2b16d319e5f7df0acc184d1 to your computer and use it in GitHub Desktop.
Save endolith/50e50ad6b2b16d319e5f7df0acc184d1 to your computer and use it in GitHub Desktop.
Display a folder of images very quickly

Give this folders as arguments, and it will display all the images in those folders as quickly as possible, letting you skim through large collections of similar images, for instance.

from tkinter import Tk, Label
from PIL import Image, ImageTk
import os
import sys
# Skip every n frames. Use 1 to show all images
skip = 1
try:
root = Tk()
image = Image.new(mode='RGB', size=(640, 480))
photo = ImageTk.PhotoImage(image)
img = Label(root, image=photo)
for folder in sys.argv[1:]:
n = 0
files = os.listdir(folder)
for filename in files[::skip]:
filename = folder + '/' + filename
try:
image = Image.open(filename)
except IOError:
continue
n += 1
photo = ImageTk.PhotoImage(image)
img.configure(image=photo)
img.pack()
root.update()
print('Displayed {} of {} files in {}'.format(n, len(files),
folder.split('\\')[-1]))
root.mainloop()
except Exception as err:
print(err)
input()
@ken-techno
Copy link

Really neat and efficient!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment