【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
相关推荐
渣渣xiong1 小时前
从零开始:前端转型AI agent直到就业第五十七天-第五十八天
前端·人工智能·python
吃好睡好便好2 小时前
创建魔方矩阵和单位矩阵
开发语言·人工智能·学习·线性代数·matlab·矩阵
影寂ldy2 小时前
C#数组的属性和方法(Clear / Copy / IndexOf )
开发语言·javascript·c#
i7i8i9com2 小时前
Hermes Agent 安装记录
开发语言·bash·hermes
小娄~~2 小时前
C语言卷子错题集
c语言·开发语言·数据结构
小L~~~2 小时前
基于贪心策略的混合遗传算法求解01背包问题
python·算法
才兄说2 小时前
机器人二次开发机器人动作定制?动作迁移数据优化
python
用户8356290780513 小时前
用 Python 实现 Excel 散点图绘制与定制
后端·python
PAK向日葵3 小时前
从零实现 Python 虚拟机(一):PVM 基本原理介绍
python
神所夸赞的夏天3 小时前
创建虚拟环境提示SSLError错误
python