Python Forum

Full Version: Trying to make random image loop in Tk window using python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I cant seem to find the right way to make a random image appear in a window (im using tk for the window), so every second a new random image from a folder appears. Haven't found a tutorial that works. this is what ive got so far but dont know how to display the image in the window:
import os
from Tkinter import *
from PIL import ImageTk, Image
import random

#the window
window=Tk()

window.title('Johnny')
window.geometry("300x200+10+20")
window.configure(background='black')
# end of window settings, content goes next:

count = 1
while count < 20:
    path="/home/david/Desktop/Johnny/Assets"
    files=os.listdir(path)
    d=random.choice(files)

window.mainloop()
any help would be very appreciated!
just for reference, Im using python3 on Linux
I think you should start by making a Tk window that changes color ever second. Once you get that working change the program to toggle between two images every second. After that write a program that makes a list of all image files in a folder. After that you should have no trouble writing a program that displays a random image that changes every second.