Support required with displaying a slideshow of Images in Python w/ TKinter
<p>I am trying to make a set of code that will open a window and displaying 6 images in sequence over and over again very quickly for 10 seconds. This is my code, however the program simply open a blank screen. What do I do? </p>

<pre><code>import time

import tkinter as tk
root = tk.Tk()
root.overrideredirect(True)
width = root.winfo_screenwidth()
height = root.winfo_screenwidth()
root.geometry('%dx%d' % (width*1, height*1))

def SS_Part1():
    image_file_ssp1 = "goat1.gif"
    image = tk.PhotoImage(file=image_file_ssp1)
    canvas = tk.Canvas(root, height=height*1, width=width*1, bg="black")
    canvas.create_image(width*1/2, height*1/2, image=image)
    canvas.pack()

def SS_Part2():
    image_file_ssp2 = "goat2.gif"
    image = tk.PhotoImage(file=image_file_ssp2)
    canvas = tk.Canvas(root, height=height*1, width=width*1, bg="black")
    canvas.create_image(width*1/2, height*1/2, image=image)
    canvas.pack()

def SS_Part3():
    image_file_ssp3 = "goat3.gif"
    image = tk.PhotoImage(file=image_file_ssp3)
    canvas = tk.Canvas(root, height=height*1, width=width*1, bg="black")
    canvas.create_image(width*1/2, height*1/2, image=image)
    canvas.pack()

def SS_Part4():
    image_file_ssp4 = "goat4.gif"
    image = tk.PhotoImage(file=image_file_ssp4)
    canvas = tk.Canvas(root, height=height*1, width=width*1, bg="black")
    canvas.create_image(width*1/2, height*1/2, image=image)
    canvas.pack()

def SS_Part5():
    image_file_ssp5 = "goat5.gif"
    image = tk.PhotoImage(file=image_file_ssp5)
    canvas = tk.Canvas(root, height=height*1, width=width*1, bg="black")
    canvas.create_image(width*1/2, height*1/2, image=image)
    canvas.pack()

def SS_Part6():
    image_file_ssp6 = "goat6.gif"
    image = tk.PhotoImage(file=image_file_ssp6)
    canvas = tk.Canvas(root, height=height*1, width=width*1, bg="black")
    canvas.create_image(width*1/2, height*1/2, image=image)
    canvas.pack()




t_end = time.time() + 10
while time.time() &lt; t_end:

    SS_Part1()
    time.sleep(0.05)
    SS_Part2()
    time.sleep(0.05)
    SS_Part3()
    time.sleep(0.05)
    SS_Part4()
    time.sleep(0.05)
    SS_Part5()
    time.sleep(0.05)
    SS_Part6()

root.mainloop()
</code></pre>

<p>These are some changes in your code, It should work properly.</p>

<pre><code>import tkinter as tk
from itertools import cycle

# foreign library, need to installed
from ImageTk import PhotoImage

images = ["first1.jpg", "first2.jpg", "first3.jpg", "first4.jpg"]
photos = cycle(PhotoImage(file=image) for image in images)

def slideShow():
  img = next(photos)
  displayCanvas.config(image=img)
  root.after(50, slideShow) # 0.05 seconds

root = tk.Tk()
root.overrideredirect(True)
width = root.winfo_screenwidth()
height = root.winfo_screenwidth()
root.geometry('%dx%d' % (640, 480))
displayCanvas = tk.Label(root)
displayCanvas.pack()
root.after(10, lambda: slideShow())
root.mainloop()
</code></pre>

<p>This is the Object-Oriented version of the above code, <strong><em>Recommended</em></strong>. Below code will work perfectly for the full screen slideshow</p>

<pre><code>from itertools import cycle
import tkinter as tk

# foreign library, need to installed
from ImageTk import PhotoImage 

images = [ "first1.jpg", "first2.jpg", "first3.jpg", "first4.jpg"]

class Imagewindow(tk.Tk):
  def __init__(self):
    tk.Tk.__init__(self)
    self.photos = cycle(
      PhotoImage(file=image) for image in images
    )
    self.displayCanvas = tk.Label(self)
    self.displayCanvas.pack()

  def slideShow(self):
    img = next(self.photos)
    self.displayCanvas.config(image=img)
    self.after(50, self.slideShow) # 0.05 seconds

  def run(self):
    self.mainloop()


root = Imagewindow()
width = root.winfo_screenwidth()
height = root.winfo_screenwidth()
root.overrideredirect(True)
root.geometry('%dx%d' % (width*1, height*1))
root.slideShow()
root.run()
</code></pre>

python tkinter gif