create thumbs in memory but don' cache to files ""thumbs [for imgfile in os listdir(imgdir)imgpath os path join(imgdirimgfiletryimgobj image open(imgpathmake new thumb imgobj thumbnail(sizethumbs append((imgfileimgobj)exceptprint("skipping"imgpathreturn thumbs if __name__ ='__main__'imgdir (len(sys argv and sys argv[ ]or 'imagesviewer_thumbs makethumbs makethumbs mainsave viewer_thumbs viewer(imgdirkind=tkmain mainloop(layout optionsgridding the next variations on our viewer are purely cosmeticbut they illustrate tkinter layout concepts if you look at figure - long enoughyou'll notice that its layout of thumbnails is not as uniform as it could be individual rows are fairly coherent because the gui is laid out by row framesbut columns can be misaligned badly due to differences in image shape different packing options don' seem to help (and can make matters even more askew--try it)and arranging by column frames would just shift the problem to another dimension for larger collectionsit could become difficult to locate and open specific images with just little extra workwe can achieve more uniform layout by either laying out the thumbnails in gridor using uniform fixed-size buttons example - positions buttons in row/column grid by using the tkinter grid geometry manager-- topic we will explore in more detail in the next so like the canvasyou should consider some of this code to be preview and seguetoo in shortgrid arranges its contents by row and columnwe'll learn all about the stickiness of the quit button here in example - pp \gui\pil\viewer-thumbs-grid py ""same as viewer_thumbsbut uses the grid geometry manager to try to achieve more uniform layoutcan generally achieve the same with frames and pack if buttons are all fixed and uniform in size""import sysmath from tkinter import from pil imagetk import photoimage from viewer_thumbs import makethumbsviewone viewing and processing images with pil