[python-win32] make a window transparent using win32?

Tim Roberts timr at probo.com
Tue Dec 28 22:44:10 CET 2010

Reckoner wrote:
> Using Python win32 extensions, how do you make an arbitrary window on
> winXP transparent?

I'll assume you already know how to find the window handle of your
victim window.

The key concept is that you need to set the WS_EX_LAYERED bit in the
extended styles, then set the transparency level using
SetLayeredWindowAttributes.  You can look up both APIs in MSDN for more
detailed information.

    import win32gui
    import win32con
    win32gui.SetWindowLong(handle, win32con.GWL_EXSTYLE,
    win32gui.SetLayeredWindowAttributes(handle, 0, 128, win32con.LWA_ALPHA)

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

More information about the python-win32 mailing list