""custom version that uses gridding ""win kind(win title('viewerimgdirthumbs makethumbs(imgdirif not colscols int(math ceil(math sqrt(len(thumbs)))fixed or rownum savephotos [while thumbsthumbsrowthumbs thumbs[:cols]thumbs[cols:colnum for (imgfileimgobjin thumbsrowphoto photoimage(imgobjlink button(winimage=photohandler lambda savefile=imgfileviewone(imgdirsavefilelink config(command=handlerlink grid(row=rownumcolumn=colnumsavephotos append(photocolnum + rownum + button(wintext='quit'command=win quitgrid(columnspan=colsstick=ewreturn winsavephotos if __name__ ='__main__'imgdir (len(sys argv and sys argv[ ]or 'imagesmainsave viewer(imgdirkind=tkmain mainloop(figure - displays the effect of gridding--our buttons line up in rows and columns in more uniform fashion than in figure - because they are positioned by both row and columnnot just by rows as we'll see in the next gridding can help any time our displays are two-dimensional by nature layout optionsfixed-size buttons gridding helps--rows and columns align regularly now--but image shape still makes this less than ideal we can achieve layout that is perhaps even more uniform than gridding by giving each thumbnail button fixed size buttons are sized to their images (or textby defaultbut we can always override this if needed example - does the trick it sets the height and width of each button to match the maximum dimension of the thumbnail iconso it is neither too thin nor too high assuming all thumbnails have the same maximum dimension (something our thumb-maker ensures)this will achieve the desired layout tkinter tourpart