Tk window and contents will not display

Chris Hare chare at
Sat Aug 14 20:30:59 CEST 2010

The scenario is this:

I want to loop around all of the images in a given directory (which I know will be images, but I guess I should check), show an image in a window, wait 2 seconds and show the next one and repeat that indefinitley, which will be until the user closes the window.

This is the code I extracted from the larger program and made work - sort of - in a standalone fashion.  When I run the code, each of the file names gets displayed, and I can view the images, so it has to be something I am doing wrong with this chunk of code.  

However, I don't see what the problem is.

from Tkinter import *
import time
import os
import ImageTk
import Image

class externalLoopDisplay:
    def show(self):        
        # Create a frame
        self.window = Tk()
        self.f = Frame(self.window, bg="Gray")
        self.btnRefresh = Button(self.f, text="Close", command=self.window.destroy, bg="Gray",highlightbackground="Red", highlightcolor="Green")
        self.btnRefresh.grid(row=0, column=2)

    def loopImage(self):
        dir =  "Radar/net17"
	while 1:
	    fileList = os.listdir(dir)
	    number = len(fileList)
	    c = 1
	    for gifFile in fileList:
                print "","top of for loop " + str(c) + " of " + str(number)
                print "","showing file "  + dir + "/" + gifFile
                self.window.title("Image " + str(c) + " of " + str(number))
                image = + "/" + gifFile)
                canvasWidth, canvasHeight = image.size
                self.w = Canvas(self.f, width=canvasWidth, height=canvasHeight)
                photo = ImageTk.PhotoImage(image=image)
                netRadarImage = Label(self.w, image=photo)
                netRadarImage.image = photo
                self.w.grid(row=1, column=0, columnspan=3)
                netRadarImage.grid( row=1, column=0)
		c = c + 1


More information about the Python-list mailing list