0

I think it has something to do with the while loop because when I comment it out the rest of the code works fine. The loop itself is running. There is no error, the widget just isn't opening. My code:

from Tkinter import *
from PIL import ImageTk, Image
import time
from os import listdir
from os.path import isfile, join, abspath

root=Tk()
myContainer1 = Frame(root)
myContainer1.pack()
root.attributes("-fullscreen", True)
root.bind("<Escape>", lambda e: e.widget.quit())

mypath = "E:/"  
images = [f for f in listdir(mypath) if isfile(join(mypath, f))]

length = len(images)

while True:
    for n in range(length):
        imgPath = abspath(mypath + images[n])
        image = Image.open(imgPath)
        photo = ImageTk.PhotoImage(image)
        label = Label(image=photo)
        label.image = photo
        label.pack()
        print images[n]    #for testing purposes
        time.sleep(10)

root.mainloop()
Laura
  • 23
  • 2

1 Answers1

1

That call to root.mainloop() in the bottom is what starts your widget and keeps it running, and before it you created an infinite loop, so the widget can never actually start.

This answer is probably close to what you want to achieve: how-to-create-a-timer-using-tkinter

Community
  • 1
  • 1
jamt
  • 181
  • 1
  • 5