from tkinter import from pil imagetk import photoimage <=required for jpegs and others imgdir 'imagesif len(sys argv imgdir sys argv[ imgfiles os listdir(imgdirdoes not include directory prefix main tk(main title('viewer'quit button(maintext='quit all'command=main quitfont=('courier' )quit pack(savephotos [for imgfile in imgfilesimgpath os path join(imgdirimgfilewin toplevel(win title(imgfiletryimgobj photoimage(file=imgpathlabel(winimage=imgobjpack(print(imgpathimgobj width()imgobj height()size in pixels savephotos append(imgobjkeep reference excepterrmsg 'skipping % \ % (imgfilesys exc_info()[ ]label(wintext=errmsgpack(main mainloop(run this code on your own to see the windows it generates if you doyou'll get one main window with quit button to kill all the windows at onceplus as many pop-up image view windows as there are images in the directory this is convenient for quick lookbut not exactly the epitome of user friendliness for large directoriesthe sample images directory used for testingfor instancehas imagesyielding pop-up windowsthose created by your digital camera may have many more to do betterlet' move on to the next section creating image thumbnails with pil as mentionedpil does more than display images in guiit also comes with tools for resizingconvertingand more one of the many useful tools it provides is the ability to generate small"thumbnailimages from originals such thumbnails may be displayed in web page or selection gui to allow the user to open full-size images on demand example - is concrete implementation of this idea--it generates thumbnail images using pil and displays them on buttons which open the corresponding original image when clicked the net effect is much like the file explorer guis that are now standard on modern operating systemsbut by coding this in pythonwe're able to control its behavior and to reuse and customize its code in our own applications in factwe'll tkinter tourpart