Python Forum
Trying to make random image loop in Tk window using python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to make random image loop in Tk window using python
#1
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
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 342 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  [Tkinter] Not able to get image as background in a Toplevel window finndude 4 3,839 Jan-07-2022, 10:10 PM
Last Post: finndude
  How can I loop PyAutoGUI's locateCenterOnScreen until the image is found? Tiel 2 7,542 Sep-26-2021, 09:39 AM
Last Post: Tiel
  [Tkinter] Tk window not displaying until loop has completed Ganga 8 15,163 Aug-09-2021, 06:42 PM
Last Post: Ganga
  [Tkinter] [split] [split] How to make a window stay on top knoxvilles_joker 10 6,033 May-22-2021, 03:54 AM
Last Post: knoxvilles_joker
  Scrollable big image in a window (TKinter) Prospekteur 3 4,408 Sep-14-2020, 03:06 AM
Last Post: Larz60+
  Adding an image to a tkinter window djwilson0495 2 7,997 Aug-23-2020, 11:07 AM
Last Post: ebolisa
  [Tkinter] How to make message box error stay on top of window scratchmyhead 1 8,118 May-10-2020, 10:21 PM
Last Post: scratchmyhead
  tkinter window and turtle window error 1885 3 6,624 Nov-02-2019, 12:18 PM
Last Post: 1885
  set button background with image of window background gray 3 14,354 Oct-18-2017, 08:22 AM
Last Post: gray

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020