label(selfimage=imgobjpack(print(imgpathimgobj width()imgobj height()self savephoto imgobj size in pixels keep reference on me def viewer(imgdirkind=toplevelcols=none)""make thumb links window for an image directoryone thumb button per imageuse kind=tk to show in main app windowor frame container (pack)imgfile differs per loopmust save with defaultphotoimage objs must be savederased if reclaimedpacked row frames (versus gridsfixed-sizescanvas)""win kind(win title('viewerimgdirquit button(wintext='quit'command=win quitbg='beige'pack first quit pack(fill=xside=bottomso clip last thumbs makethumbs(imgdirif not colscols int(math ceil(math sqrt(len(thumbs)))fixed or savephotos [while thumbsthumbsrowthumbs thumbs[:cols]thumbs[cols:row frame(winrow pack(fill=bothfor (imgfileimgobjin thumbsrowphoto photoimage(imgobjlink button(rowimage=photohandler lambda savefile=imgfileviewone(imgdirsavefilelink config(command=handlerlink pack(side=leftexpand=yessavephotos append(photoreturn winsavephotos if __name__ ='__main__'imgdir (len(sys argv and sys argv[ ]or 'imagesmainsave viewer(imgdirkind=tkmain mainloop(notice how this code' viewer must pass in the imgfile to the generated callback handler with default argumentbecause imgfile is loop variableall callbacks will have its final loop iteration value if its current value is not saved this way (all buttons would open the same image!also notice we keep list of references to the photo image objectsphotos are erased when their object is garbage collectedeven if they are currently being displayed to avoid thiswe generate references in long-lived list figure - shows the main thumbnail selection window generated by example - when viewing the default images subdirectory in the examples source tree (resized here for displayas in the previous examplesyou can pass in an optional directory name to run the viewer on directory of your own (for instanceone copied from your digital cameraclicking thumbnail button in the main window opens corresponding image in pop-up windowfigure - captures one tkinter tourpart