如何在Linux上检查Python3.x中是否存在窗口

如何在Linux上检查Python3.x中是否存在窗口,python,linux,windows,api,python-3.x,Python,Linux,Windows,Api,Python 3.x,我目前正试图弄清楚如何在linux上通过Python访问某种“linux api”。我的问题是,我一直想在windows上用autoit方式做事,所以我不仅要掌握新语言,还要掌握操作系统 基本上我的代码是这样的: while (1) if winexists("windowname") = 1 then kill(pid) endif wend 我可以通过windows API或直接通过autoit实现这一点,但我不确定如何在linux中实现这一点。我也没有在谷歌上找到太多相关的搜索结果。

我目前正试图弄清楚如何在linux上通过Python访问某种“linux api”。我的问题是,我一直想在windows上用autoit方式做事,所以我不仅要掌握新语言,还要掌握操作系统

基本上我的代码是这样的:

while (1)
if winexists("windowname") = 1 then
  kill(pid)
endif
wend

我可以通过windows API或直接通过autoit实现这一点,但我不确定如何在linux中实现这一点。我也没有在谷歌上找到太多相关的搜索结果。我不是在找人为我编码,只是需要指出正确的方向。

您可以使用外部程序(如
wmctrl
)输出,使用:

import subprocess

def winexists(target):
    for line in subprocess.check_output(['wmctrl', '-l']).splitlines():
        window_name = line.split(None, 3)[-1].decode()
        if window_name == target:
            return True
    return False