[Python] Python遍历windows的所有窗口并输出窗口标题的代码 →→→→→进入此内容的聊天室

来自 , 2019-09-27, 写在 Python, 查看 142 次.
URL http://www.code666.cn/view/dbea3d0e
  1. #! /usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. from win32gui import *
  5. titles = set()
  6. def foo(hwnd,mouse):
  7.   #去掉下面这句就所有都输出了,但是我不需要那么多
  8.   if IsWindow(hwnd) and IsWindowEnabled(hwnd) and IsWindowVisible(hwnd):
  9.     titles.add(GetWindowText(hwnd))
  10.  
  11. EnumWindows(foo, 0)
  12. lt = [t for t in titles if t]
  13. lt.sort()
  14. for t in lt:
  15.   print t
  16.  
  17.  
  18. #//python/9058

回复 "Python遍历windows的所有窗口并输出窗口标题的代码"

这儿你可以回复上面这条便签

captcha