我如何关闭在执行与PIL相关的python代码期间创建的窗口?

问题描述 投票:0回答:1

我一直在使用python代码在rpi上使用Pillow模块。我想显示图像,等待一秒钟,然后关闭图像。我使用的代码会打开一个窗口,上面显示图像,这是我需要在打开第二秒后关闭的窗口...

在给出代码之前,我使用rpi上的终端安装了以下文件,仅供参考

sudo pip3 install Pillow

我的代码是:

from PIL import Image
import time


Img=Image.open("A.PNG") #A.PNG is the Image name
Img.show #Showing Image
time.sleep(1) #Wait for 1 second
##Here I need to close the window which has

打开的图像

我如何使用此代码...或其他任何选择。希望您能得到我想要的代码,通过解决上述问题或通过其他方法,可以解决问题的任何事物都会受到赞赏。

python python-3.x python-imaging-library raspberry-pi3
1个回答
0
投票
#007_py_process_kill_processname_dispaly
import os
import string
#
cnt=0
fnam='ps.txt'
os.system('ps -e>'+fnam)
psf=open(fnam, 'r')
for li in psf: # line by line from ps.txt
    l=psf.readline()
    lps=l.split()
    pid=int(lps[0]) #process id
    psnam=lps[3]    #process name
    if(psnam=='display'): # image show() process
        print( lps[0],lps[1], lps[2],lps[3])
        os.kill(pid,9)
        cnt +=1
    if(psnam=='sh'): break # the last process name
print('killed total= %d'%cnt)
© www.soinside.com 2019 - 2024. All rights reserved.