【Python-第三方库-pywin32】随笔- Python通过`pywin32`获取窗口的属性

Python通过pywin32获取窗口的属性

基础

获取所有窗口的句柄

【代码】
python 复制代码
import win32gui


def get_all_windows():
    hWnd_list = []
    win32gui.EnumWindows(lambda hWnd, param: param.append(hWnd), hWnd_list)
    print(hWnd_list)
    return hWnd_list
【结果】
cmd 复制代码

获取窗口的子窗口句柄

【代码】
python 复制代码
import win32gui


def get_son_windows(parent):
      hWnd_child_list = []
      win32gui.EnumChildWindows(parent, lambda hWnd, param: param.append(hWnd), hWnd_child_list)
      print(hWnd_child_list)
      return hWnd_child_list
【结果】
cmd 复制代码

获取窗口的标题

【代码】
python 复制代码
import win32gui


def get_title(hwnd):
    title = win32gui.GetWindowText(hwnd)
    print('窗口标题:%s' % (title))
    return title
【结果】
cmd 复制代码
窗口标题:设置

获取窗口的类名

【代码】
python 复制代码
import win32gui


def get_clasname(hwnd):
    clasname = win32gui.GetClassName(hwnd)
    print('窗口类名:%s' % (clasname))
    return clasname
【结果】
cmd 复制代码
窗口类名:ApplicationFrameWindow
相关推荐
treasure140几秒前
Django复习笔记(2026年10月)
后端·python·django·api·web·drf
iCxhust3 分钟前
C#双时区时钟设计
开发语言·c#
sbjdhjd11 分钟前
从污点追踪断点到 PHP-FPM 请求队列:HIDS PHP WebShell 样本复盘
开发语言·网络安全·数据挖掘·渗透测试·开源·php·shell
xiaoqiangclub18 分钟前
Python 的实验性 JIT 要生变?那个开关现在还该不该开
python·性能优化·jit·开发环境·cpython
2601_9679873721 分钟前
终端 IDE 卷到了新高度:个人免费,符号索引快 65%,内存省 95%
ide·python·免费·性能·rune
全栈陈序员25 分钟前
【Python】基础语法入门(三十一)—— API 开发:用 FastAPI 构建 RESTful 接口
python·restful·fastapi
SEO_juper41 分钟前
Go 站点地图生成器:从首页爬全站,一键生成 sitemap.xml
xml·开发语言·人工智能·golang·node.js·seo·外贸独立站
懂点Tech8 小时前
ctfshow misc28:GIF 高度修改解题与脚本实现
开发语言·windows·python
comedate9 小时前
SMLib 的 Examples 导读:PyAPI / SM_API / SMLib 三组示例怎么读
python·cad·smlib·examples·sm_api
云和数据.ChenGuang9 小时前
Python 重写(Override)深度解析:从 MRO 到 super() 的完整机制
java·开发语言·人工智能·python·langchain·1024程序员节