Dextron
Dextron

Reputation: 628

Use win32 module to have a transparent Python window

I want to be able to have the Python program itself transparent, but all I could find was running other programs and making them transparent, which is not what I want to do. I just want to make the Python program itself transparent using the win32 module.

Upvotes: 4

Views: 1246

Answers (1)

Dextron
Dextron

Reputation: 628

So after playing around with a test i did in pygame and reading the answer from here: https://stackoverflow.com/questions/4549213/make-a-window-transparent-using-win32

I managed to get it to work and I also can change colour with colorama so that's good. Here's my code:

import win32gui,win32api,win32con

hwnd = win32gui.FindWindow(None, title)
        win32gui.SetWindowLong(hwnd, win32con.GWL_EXSTYLE, win32gui.GetWindowLong(hwnd, win32con.GWL_EXSTYLE) | win32con.WS_EX_LAYERED)
        win32gui.SetLayeredWindowAttributes(hwnd, win32api.RGB(0,0,0), 180, win32con.LWA_ALPHA)

So for some strange reason whenever i try to make the program transparent before my loop starts in my program I get a error about "invalid window handle". I do change the program title but I change it before i try the transparency and i update the title with the trancparancy.

Upvotes: 3

Related Questions