python获取window所有窗口信息

  • Post author:
  • Post category:python


import win32gui

def demo_top_windows():
    '''
    演示如何列出所有的顶级窗口
    :return:
    '''
    hWndList = []
    win32gui.EnumWindows(lambda hWnd, param: param.append(hWnd), hWndList)
    for hWnd in hWndList:
        title = win32gui.GetWindowText(hWnd)
        title = title.encode().decode('utf-8')
        clsname = win32gui.GetClassName(hWnd)
        print(hWnd,title,clsname)
        # hWnd windows pid
        # title 窗口标题
        # clsname 窗口类名
    print(hWndList)
demo_top_windows()



版权声明:本文为weixin_41201496原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。