title: Tkinter image stream
body: <p>I am new to Python and I am trying to make a program that displays a sequence of screenshots one after another indefinitely to stream the screen of an iOS device. I am trying to recreate the Python program used in the <a href="https://www.youtube.com/watch?v=3TWCSfBhtss" rel="nofollow noreferrer">Trustjacking demo by Symantec to simulate the videojacking attack</a>.</p>
  
  <p>This is the code I have so far</p>
  
  <pre><code>from tkinter import *
  import tkinter
  from PIL import Image
  from PIL import ImageTk
  import os
  
    while True:
  
      def stream():
  
        root = Tk()
  
        os.system("sudo idevicescreenshot test.jpg | sudo tee /proc/sys/vm/drop_caches &gt;/dev/null 2&gt;&amp;1")
  
        width = 500
        height = 700
        img = Image.open("/Desktop/test.jpg")
        img = img.resize((width,height), Image.ANTIALIAS)
        photoImg =  ImageTk.PhotoImage(img)
        b = Button(root,image=photoImg, width=500)
        b.pack()
        os.system("rm -rf /Desktop/test.jpg")
        root.mainloop()
      stream()
  </code></pre>
  
  <p>But it only moves to the next image when you close the Tkinter window. The program in the demo cycles through the screenshots without closing the Tkinter window so, closing and reopening the window is not an option. I cannot figure out how to take the screenshots and then cycle through them one after another in one Tkinter window to create a stream. Any suggestions on how I can solve this problem?</p>