Python实现遍历windows所有窗口并输出窗口标题的方法
本文实例讲述了Python实现遍历windows所有窗口并输出窗口标题的方法。分享给大家供大家参考。具体如下:
这段代码可以让Python遍历当前Windows下所有运行程序的窗口,并获得运行窗口的标题输出
#! /usr/bin/env python # -*- coding: utf-8 -*- from win32gui import * titles = set() def foo(hwnd,mouse): #去掉下面这句就所有都输出了,但是我不需要那么多 if IsWindow(hwnd) and IsWindowEnabled(hwnd) and IsWindowVisible(hwnd): titles.add(GetWindowText(hwnd)) EnumWindows(foo, 0) lt = [t for t in titles if t] lt.sort() for t in lt: print t
若要输出中文,可以将最后一句改成:
print(t.decode('GB2312'))
将GB2312转码成Unicode输出,这样输出的窗口标题就是正常的中文。
希望本文所述对大家的Python程序设计有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Regarding the problem of removing the Python interpreter that comes with Linux systems, many Linux distributions will preinstall the Python interpreter when installed, and it does not use the package manager...

Pylance type detection problem solution when using custom decorator In Python programming, decorator is a powerful tool that can be used to add rows...

About Pythonasyncio...

Using python in Linux terminal...

Error loading Pickle file in Python 3.6 environment: ModuleNotFoundError:Nomodulenamed...

Mastering Debian system log monitoring is the key to efficient operation and maintenance. It can help you understand the system's operating conditions in a timely manner, quickly locate faults, and optimize system performance. This article will introduce several commonly used monitoring methods and tools. Monitoring system resources with the sysstat toolkit The sysstat toolkit provides a series of powerful command line tools for collecting, analyzing and reporting various system resource metrics, including CPU load, memory usage, disk I/O, network throughput, etc. The main tools include: sar: a comprehensive system resource statistics tool, covering CPU, memory, disk, network, etc. iostat: disk and CPU statistics. mpstat: Statistics of multi-core CPUs. pidsta

The problem and solution of the child process continuing to run when using signals to kill the parent process. In Python programming, after killing the parent process through signals, the child process still...

Solve the problem of errors in creating a scaffolding project by HttpRunner. When using HttpRunner for interface testing, its scaffolding function is often used to create a project. �...
