I was trying to make a pygame window background transparent, I did it with this code:
import win32gui, win32con, win32api
import pygame
pygame.init()
w,h = 400,200
screen = pygame.display.set_mode((w,h))
#font
pygame.font.init()
font1 = pygame.font.SysFont("Arial",128)
# Create layered window
hwnd = pygame.display.get_wm_info()["window"]
win32gui.SetWindowLong(hwnd, win32con.GWL_EXSTYLE,
win32gui.GetWindowLong(hwnd, win32con.GWL_EXSTYLE) | win32con.WS_EX_LAYERED)
# Set window transparency color
transp = (255, 0, 128) # Transparency color
win32gui.SetLayeredWindowAttributes(hwnd, win32api.RGB(*transp), 0, win32con.LWA_COLORKEY)
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit()
#Drawing text
screen.fill(transp)
text = font1.render("hello",True,(255,255,255))
screen.blit(text, (40,40))
pygame.display.update()
It works fine until I try to draw images with antialiasing;
this is what happens:

The pixels with transparent alpha value become fuchsia :( I've seen that this can be fixed using win32gui.UpdateLayeredWindow() but I didn't find any way to do it in a pygame window. If someone can help me I would be really grateful.
From the comment posted by Exlife (with copy edits):