title: Tkinter slideshow with buttons
body: <p>i want to code a slideshow that changes the image after a button is pressed. I also want to be able to change images in both directions.</p>
  
  <p>Obviously i found some code that somewhat fits but not exactly how i want it.
  class ImageViewer(tk.Tk):</p>
  
  <pre><code>import glob
  import tkinter as tki
  from PIL import Image, ImageTk
  
  
  class ImageViewer(tki.Tk):
      def __init__(self):
          """Create the ImageViewer."""
          # Attributes for the image handling.
          self.image_names=glob.glob('/home/pi/Images/*.png')
          self.index = 0
          self.photo = None
          #Button init
          btn= tki.Button(self.root,text="NextPic",command=self.show_image)
          btn.grid(sticky = tki.S)
          # We'll use a Label to display the images.
  
          self.label = tk.Label(self)
          self.label.pack(padx=5, pady=5)
          # Delay should be in ms.
          self.delay = 1000*2.5
          # Display the first image.
          self.show_image()
  
      def show_image(self):
          """Display an image."""
          # We need to use PIL.Image to open png files, since
          # tkinter's PhotoImage only reads gif and pgm/ppm files.
          image = Image.open(self.image_names[index])
          # We need to keep a reference to the image!
          self.photo = ImageTk.PhotoImage(image)
          self.index += 1
          if self.index == len(self.image_names):
              self.index = 0
          # Set the image
          self.label['image'] = self.photo
          # Tell tkinter we want this method to be called again after a delay.
          self.after(self.delay, show_image)
  
  root = ImageViewer()
  root.mainloop()
  </code></pre>
  
  <p>This is the error:</p>
  
  <pre><code>   File "slideshow.py", line 41, in &lt;module&gt;
          root = ImageViewer()
        File "slideshow.py", line 19, in __init__
          btn= tki.Button(self.root, text="Next Pic", command=self.show_image)
        File "/usr/lib/python3.5/tkinter/__init__.py", line 1961, in __getattr__
          return getattr(self.tk, attr)
        File "/usr/lib/python3.5/tkinter/__init__.py", line 1961, in __getattr__
          return getattr(self.tk, attr)
        File "/usr/lib/python3.5/tkinter/__init__.py", line 1961, in __getattr__
          return getattr(self.tk, attr)
  RecursionError: maximum recursion depth exceeded
  </code></pre>
  
  <p>The part before Recursion Error is printed many more times so i cut it short.</p>