|
1
|
Using PIL and Tkinter you can easily display images in a window.
The PIL Image class has a show() method to display an image. This works OK, but it is slow as it must save the image to a temporary file and then launch an external application to display it. What is even more annoying is that you cannot easily reuse the display window. I often use PIL to create video filters that iterate over thousands of video frames. I like to display each frame after I am done processing it so I can observe how the image processing is progressing. You can't do this with Image.show() because you would end up with thousands of open windows. Note that I'm using the Tkinter mainloop backwards from a typical event-oriented Tk application. Normally the Button event would control the iteration and display of file. Instead, I just break out of the mainloop. I do this because this way is simpler and better fits the model for a batch processing script. I just want to update a window with an image. I don't intend to have a more elaborate interface.
Tags: graphics
|
3 comments
Add a comment
Sign in to comment

Download
Copy to clipboard

how to show next and back image? Thanks.But, how to show next image clicked to Button-1 and show back image clicked to Button-3 , or special key left-right ?
Nice piece of code, I would consider adding root.destroy() after the for-loop, to clean up a little. I know from running this on windows the window created just hangs on the screen and you cannot close it when it reaches the end of the loop.
How will you modify this, if you want to show two images simultaneously? say side by side?