Python Forum
Closing an image opened by Pillow in Window Photo Viewer
Thread Rating:
  • 2 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Closing an image opened by Pillow in Window Photo Viewer
#1
I'm trying to close each image opened via iteration, within each iteration.




for i in Final_Bioteck[:5]:
     with Image.open('{}_screenshot.png'.format(i)) as test_image:
        test_image.show()
        time.sleep(2)
 My code doesn't seem to close the photos opened via Windows Photo Viewer. 
I also tried,



test_image.close()

 , but no result.





My loop above is opening 5 Windows Photos Viewer dialogs; I was hoping that as I loop through each iteration, each window would be closed.


Thank you.
Reply
#2
since you used 'with', no close should be necessary
The image should close after the sleep, automatically
Reply
#3
(May-01-2017, 04:00 PM)Larz60+ Wrote: since you used 'with', no close should be necessary
The image should close after the sleep, automatically

Yeah, it doesn't seem to be closing with or without 'close.' Not sure why.
Reply
#4
It may be closed, but screen not refreshed.
If it was drawn on a canvas, try rewriting the canvas
Reply
#5
(May-01-2017, 04:32 PM)Larz60+ Wrote: It may be closed, but screen not refreshed.
If it was drawn on a canvas, try rewriting the canvas



Sorry, I'm not sure what you mean by canvas. 
The images are screenshots, and are being opened by Windows Photo Viewer.
Reply
#6
https://pillow.readthedocs.io/en/4.1.x/r...Image.show Wrote:Image.show(title=None, command=None)
Displays this image. This method is mainly intended for debugging purposes.

Emphasis mine.
There probably isn't meant to be a way to close it, since opening it is just for debugging to make sure things are working.
Reply
#7
(May-01-2017, 08:17 PM)nilamo Wrote:
https://pillow.readthedocs.io/en/4.1.x/r...Image.show Wrote:Image.show(title=None, command=None)
Displays this image. This method is mainly intended for debugging purposes.

Emphasis mine.
There probably isn't meant to be a way to close it, since opening it is just for debugging to make sure things are working.


I see. Any suggestions as to what I should do?
Reply
#8
I guess it depends on what you're trying to accomplish. Why do you want to flash some images on the screen and immediately close them?

Since you're using the PIL already, there's ImageTk, which can display images in a Tk window: http://effbot.org/imagingbook/imagetk.htm
Or you can use something like pygame to open a few windows and blit the images, or use Tk directly, etc.
Reply
#9
(May-02-2017, 04:01 PM)nilamo Wrote: I guess it depends on what you're trying to accomplish.  Why do you want to flash some images on the screen and immediately close them?

Since you're using the PIL already, there's ImageTk, which can display images in a Tk window: http://effbot.org/imagingbook/imagetk.htm
Or you can use something like pygame to open a few windows and blit the images, or use Tk directly, etc.


I have about 200 stock charts I want to look at, and I just need to look at them for a few seconds each. 
I want to automate this process.
Reply
#10
Ok, I think I'd try to use pygame then.
Loading the image as a surface: https://www.pygame.org/docs/ref/image.ht...image.load
Once it's a surface, you can draw it to the screen just as any other surface in pygame, so this guide can help with the rest: https://python-forum.io/Thread-PyGame-Lo...ets-part-2
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Is there a way to call and focus any popup window outside of the main window app? Valjean 6 1,613 Oct-02-2023, 04:11 PM
Last Post: deanhystad
  aoigram, pil Help with photo processing kolpac21 0 529 Aug-07-2023, 04:59 PM
Last Post: kolpac21
  does not save in other path than opened files before icode 3 833 Jun-23-2023, 07:25 PM
Last Post: snippsat
  Tkinter Pillow Resize Image Looks Choppy While Resizing AaronCatolico1 2 1,326 Jan-03-2023, 05:41 PM
Last Post: AaronCatolico1
  Pyspark Window: perform sum over a window with specific conditions Shena76 0 1,132 Jun-13-2022, 08:59 AM
Last Post: Shena76
Question How to get html information from a tab of my default browser opened with webbrowser? noahverner1995 2 4,336 Jan-14-2022, 10:02 AM
Last Post: noahverner1995
  Closing Threads and the chrome window it spawned from Tkinter close button law 0 1,670 Jan-08-2022, 12:13 PM
Last Post: law
  Rmarkdown opened by python code - errors Rav013 0 2,049 Apr-27-2021, 03:13 PM
Last Post: Rav013
  Invert Pillow image colours chesschaser 5 3,606 Jul-11-2020, 02:59 PM
Last Post: chesschaser
  Add Photo in Python adninqasifa 4 5,814 Nov-26-2018, 06:06 PM
Last Post: adninqasifa

Forum Jump:

User Panel Messages

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