[python-win32] get window title

Tim Roberts timr at probo.com
Tue Dec 9 20:41:10 CET 2008

Billy Pilgrim wrote:
> I am rather new to python and haven't been able to find a solution to
> this (in python or in any other language). 
> The problem:  I am trying to find a way to iterate over the set of
> open windows, and retrieve/extract the window title. 
> The real project, stupid as it is, is to find the 'Freecell' window
> and extract the game number -- which is part of the title. 

I hesitate to turn on my sarcasm generator, but I find it hard to
believe that you actually looked for a solution to this.  Any number of
good Google phrases should have brought you the pieces you need to make
this happen.

import win32gui

def winEnumHandler( hwnd, ctx ):
    if win32gui.IsWindowVisible( hwnd ):
        print hex(hwnd), win32gui.GetWindowText( hwnd )

win32gui.EnumWindows( winEnumHandler, None );

Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.

More information about the python-win32 mailing list