2017-05-01 34 views
1

私は、各反復で繰り返し開いた画像を閉じようとしています。Window Photo ViewerでPillowで開いた画像を閉じる

私は以下のこのスレッドを参照しましたが、正解は結果を生成していません。

How do I close an image opened in Pillow?

私のコード

for i in Final_Bioteck[:5]: 
    with Image.open('{}_screenshot.png'.format(i)) as test_image: 
     test_image.show() 
     time.sleep(2) 

私も試してみました、

test_image.close()、ない結果。

私の上記のループが開きます5 Windows Photos Viewerダイアログ。私は反復を通して、各ウィンドウが閉じられることを望んでいました。

私はこのスレッドも見ましたが、答えはかなり古くなっていますので、私が望むものを実行するためのより簡単な方法があるかどうかはわかりません。 How can I close an image shown to the user with the Python Imaging Library?

)=ありがとう

答えて

2

は作業それを得たが、私はデフォルトのビューアの.exeファイルを見つけることができなかったように私は、Windows上の異なる画像ビューアをインストールしました。

import webbrowser 
import subprocess 
import os, time 

for i in Final_Bioteck[6:11]: 
     webbrowser.open('{}.png'.format(i)) # opens the pic 
     time.sleep(3) 
     subprocess.run(['taskkill', '/f', '/im', "i_view64.exe"]) 

#taskkill kills the program, '/f' indiciates it's a process, '/'im' (not entirely sure), and i_view64.exe is the image viewers' exe file. 
関連する問題