Search code examples
pythonautomationpywinauto

How to make a window transparent with pywinauto?


I have a window that can't be minimized.
I have to prevent users to access it while the gui automation.
How to handle this kind of problems with pywinauto?

It works with autoit and the WinSetTrans() function.
Is there something similar in the pywinauto module?


Solution

  • There is no such method in pywinauto, but it's easy to implement. Thank you for the feature request!

    So far you may workaround it so:

    import win32gui, win32api, win32con
    
    hwnd = app.dlg.ctrl.handle
    ex_style = app.dlg.ctrl.ExStyle()
    win32gui.SetWindowLong (hwnd, win32con.GWL_EXSTYLE, ex_style | win32con.WS_EX_LAYERED )
    win32gui.SetLayeredWindowAttributes(hwnd, win32api.RGB(0,0,0), 180, win32con.LWA_ALPHA)
    

    P.S. It was quickly adapted from the known answer (I didn't check it yet). We will include something like SetTransparent method into pywinauto 0.5.3 (planning this week).