as once you click on a thumbnail to display the image?
Question: please help to fix the script.

    
    
    import os, sys
    import tkinter
    from PIL import ImageTk, Image
    
    DIR_IMGS = 'imgs'
    DIR_THUMBS = 'thumbs'
    imgfiles = os.listdir(DIR_IMGS)
    thumbfiles = os.listdir(DIR_THUMBS)
    
    root = tkinter.Tk()
    root.geometry('900x700')
    links = []
    
    
    def showItem(imgfile):
        print(imgfile)
        pathImg = os.path.join(DIR_IMGS, imgfile)
        print(pathImg)
        renderImg = ImageTk.PhotoImage(file=pathImg)
        popup = tkinter.Toplevel()
        tkinter.Button(popup, image=renderImg).pack()   
    
    
    def createThumbs():
        for imgfile in imgfiles:
            pathImg1 = os.path.join(DIR_IMGS, imgfile)
            pathImg2 = os.path.join(DIR_THUMBS, imgfile)
    
            openImg = Image.open(pathImg1)
            openImg.thumbnail((100, 100))
            openImg.save('thumbs/' + imgfile)
    
    
    def outputButtons():
        for thumbfile in thumbfiles:
            pathImg = os.path.join(DIR_THUMBS, thumbfile)
            renderImg = ImageTk.PhotoImage(file=pathImg)
            but = tkinter.Button(root, image=renderImg)
            but.pack(side='left')
            but.bind('<Button-1>', lambda event, thumbfile=thumbfile: showItem(thumbfile))
            links.append(renderImg)
    
    
    createThumbs()
    outputButtons()
    
    root.mainloop()
    

I wrote the script, just the example of the popular book "Mark Lutz.
Programming Python". but for some strange reason, my script does not work.

no manifest error as the screen is not an error message. but in pop-up window
is not displayed (showing blank popup)


Answer: The (somewhat large) image is garbage collected before the window has a chance
to display it. You'll need to keep a reference around to the image to show it.
I've taken the solution from
[here](http://compgroups.net/comp.lang.python/tkinter-buttons-with-
image/1637656), and your `showItem` function can look as follows:

    
    
    def showItem(imgfile):
        print(imgfile)
        pathImg = os.path.join(DIR_IMGS, imgfile)
        print(pathImg)
        renderImg = ImageTk.PhotoImage(file=pathImg)
        popup = tkinter.Toplevel()
        button = tkinter.Button(popup, image=renderImg)
        button.image = renderImg
        button.pack()   
    

