Tkinter Image Viewer Method
I would replace the current loop function with something like the following (untested). The changes: add some global names to share data between functions; make change_image do everything needed to change an image, given that current_image is valid; except for the starting value, make current_image be always a valid image number when it is changed; factor forward() out of animate() (which is just repeated times forward calls).
n_images = 2images = [PhotoImage(file="filename"+str(i)+".gif") for i in range(n_images)]current_image = -1def change_image(): displayFrame.delete('Animate') displayFrame.create_image(0,0, anchor=NW, image=StaticFrame[current_image], tag='Animate') displayFrame.update_idletasks() #Force redrawcallback = Nonedef animate(): global callback forward() callback = root.after(1000, animate)
Here are three of the other functions.
def forward(): global current_image current_image += 1 if current_image >= n_images: current_image = 0 change_image()def back(): global current_image current_image -= 1 if current_image < 0: current_image = n_images-1 change_image()def stop(): if callback is not None: root.after_cancel(callback)