如何为 Python 中的 Windows hwnd 设置透明键?

How can I set the transparency key for a Windows hwnd in Python?

我希望使我的 wxPython window(并且只有背景)的背景透明。

在 Windows 中,表单可以有一个 transparency key. 这允许用户通过将背景设置为透明键颜色来提供 windows "transparent" 背景。

在 wx 中似乎没有执行此操作的选项。鉴于我的 window 的 HWND,我该如何直接设置它?

墨菲定律,一问就找到了答案

win32gui模块有设置透明键的功能。

win32gui.SetLayeredWindowAttributes


SetLayeredWindowAttributes(hwnd, Key, Alpha, Flags)

    Sets the opacity and transparency color key of a layered window.

Parameters

    hwnd : PyHANDLE

        handle to the layered window

    Key : int

        Specifies the color key. Use win32api::RGB to generate value.

    Alpha : int

        Opacity, in the range 0-255

    Flags : int

        Combination of win32con.LWA_* values