How to close after PIL.image show of python

python opens the default photo viewer after PIL.image show. Is there a way to close it. Or can only end the process

Mar.31,2021

can take a handle snapshot of all hwnd windows before show. Then a snapshot comparison is made after show. You can also use lower-level WIN32 hooks to monitor window changes.


pillow does not provide a method to close.

according to the PIL document https://pillow.readthedocs.io.

and source code

if sys.platform == "win32":

    class WindowsViewer(Viewer):
        format = "BMP"

        def get_command(self, file, **options):
            return ('start "Pillow" /WAIT "%s" '
                    '&& ping -n 2 127.0.0.1 >NUL '
                    '&& del /f "%s"' % (file, file))

    register(WindowsViewer)
Menu