Display image with Tkinter and loop over time
I am currently using the PIL and Tkinter to display images. I am streaming in images from a network and want to update my window automatically as the come in (much like a picture slideshow). My code for displaying images works; however, i have to click the [x] button on the display window for the photo to update. I want the window to automatically update as the new photo comes in, or at the very least, run the loop like every 5 seconds (so the window either closes itself and a n开发者_StackOverflowew photo appears, or the photo just changes in the window). My code is:
##I have a database of photos i want to display one by one...
im=image.open(currentphoto)
root=Tk()
canvas=...
photo=imageTk.PhotoImage(im)
item=canvas.create_image(10,10,anchor=NW,image=photo)
root.mainloop()
##want to display next photo either as it comes in or every 5 seconds (whichever is easier -- first method preferred)
This code works;
Call the method after
to schedule a command to run in the future. It's perfectly legal for this command to also call after
to schedule itself to run again in the future.
For an example that shows a Label getting its text updated every second, see this answer to another question here on SO.
精彩评论