Shows how to create a basic slide show with the Python Tkinter GUI toolkit.

Gribouillis commented: good tkinter example +14
create a Tkinter image repeating slide show
tested with Python27/33  by  vegaseat  03dec2013

from itertools import cycle

    # Python2
    import Tkinter as tk
except ImportError:
    # Python3
    import tkinter as tk

class App(tk.Tk):
    '''Tk window/label adjusts to size of image'''
    def __init__(self, image_files, x, y, delay):
        # the root will be self
        # set x, y position only
        self.geometry('+{}+{}'.format(x, y))
        self.delay = delay
        # allows repeat cycling through the pictures
        # store as (img_object, img_name) tuple = cycle((tk.PhotoImage(file=image), image)
                              for image in image_files)
        self.picture_display = tk.Label(self)

    def show_slides(self):
        '''cycle through the images and show them'''
        # next works with Python26 or higher
        img_object, img_name = next(
        # shows the image filename, but could be expanded
        # to show an associated description of the image
        self.after(self.delay, self.show_slides)

    def run(self):

# set milliseconds time between slides
delay = 3500

# get a series of gif images you have in the working folder
# or use full path, or set directory to where the images are
image_files = [

# upper left corner coordinates of app window
x = 100
y = 50

app = App(image_files, x, y, delay)
About the Author
Member Avatar vegaseat DaniWeb's Hypocrite


Works nicely!

Please upload the gifs !

For some odd reason I don't remember how to upload gifs on DaniWeb.
Any help?

In the editor, click on the paper clip, then browse your files. You may need to zip a folder with the gifs :)

Thanks a lot, here we go ...

Very nice, it works very well.

It is my understanding that you use Linux or the Apple OS X?

Linux mint 15 Olivia 64 bits KDE.

Hello i get the error message. When i try to use all gifs in a folder. How do i correct this issue ?

C:\Python27\python.exe C:/Users/Klova/PycharmProjects/untitled/
Traceback (most recent call last):
File "C:/Users/Klova/PycharmProjects/untitled/", line 59, in <module>

C:\Python27\python.exe C:/Users/Klova/PycharmProjects/untitled/
Traceback (most recent call last):
  File "C:/Users/Klova/PycharmProjects/untitled/", line 59, in <module>
  File "C:/Users/Klova/PycharmProjects/untitled/", line 33, in show_slides
    img_object, img_name = next(
  File "C:/Users/Klova/PycharmProjects/untitled/", line 26, in <genexpr>
    for image in image_files)
  File "C:\Python27\lib\lib-tk\", line 3362, in __init__
    Image.__init__(self, 'photo', name, cnf, master, **kw)
  File "C:\Python27\lib\lib-tk\", line 3316, in __init__'image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't open "C:\Users\Klova\Desktop\Snapfie": permission denied
HiHe 174

The line
for image in image_files)
is in your error code but not in the original snippet.
So, if you doctored up the snippet code, we would have to be mind readers to help you.

Can you tell me how to modify this to display jpg rather than gif pictures please?

@micksulley This snippet shows how to open a jpeg image with PIL in order to display it with tkinter. I think it should work for you.

Many thanks, I will give that a try.

Sorry but I cannot get this to work for jpg. I assume that I need to change line 25, 30 but cannot figure out how to do it. I have tried many different things an none have worked.
I think my biggest problem is that I don't really understand those lines. I see what cycle does normally but in this case it seems to be returning two values tk.PhotoImage(file=image) and image, is that the case? I expected it to just return a file name, have I misunderstood what is happening?

Many thanks

You can add

from PIL import Image, ImageTk
import io

at the top, then add a method in class App:

def photo_image(self, jpg_filename):
    with, 'rb') as ifh:
        pil_image =
        return ImageTk.PhotoImage(pil_image)

Then at line 25, replace tk.PhotoImage(file=image) with self.photo_image(image).

Notice that this code keeps all the images in memory at the same time while running the slideshow.

Yes I guess memory may be the next problem, I will investigate.
Thanks for your help.

Hey! Cool script! I got a few questions though. First off, how do you make the script stop after the last picture in the picture list? Secondly, do you know how to make the pictures display at say half the resolution?

guys, i want the code to automatically scan all the images in the folder and display them one by one in slideshow manner...please help

how to add the path of the folder instead of adding images path one by one in the code

very nice code and also very useful!
one question, i don't understand very well how line 19 works ("tk.Tk.init(self)"), can someone explain it to me?