How can I keep a full screen PyGame window on top?
I have written a simple program below that creates a screen overlay and draws a circle on it. The overlay can be clicked through and content behind the overlay can be interacted with.
import pygame
import win32api
import win32con
import win32gui
pygame.init()
screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
transparent = (74, 65, 42)
window_info = pygame.display.get_wm_info()["window"]
win32gui.SetWindowLong(window_info, win32con.GWL_EXSTYLE, win32gui.GetWindowLong(window_info, win32con.GWL_EXSTYLE) | win32con.WS_EX_LAYERED)
win32gui.SetLayeredWindowAttributes(window_info, win32api.RGB(*transparent), 0, win32con.LWA_COLORKEY)
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RCTRL:
running = False
screen.fill(transparent)
pygame.draw.circle(screen, (255, 255, 255), (150, 150), 75)
pygame.display.flip()
pygame.quit()
My problem is that when I interact with the windows behind the overlay, it moves the overlay to the back. I want to be able to pin the overlay on top but still be able to interact with the background items.
I have tried using functions of the win32gui and tried code from https://stackoverflow.com/a/25383929/14335807 and https://stackoverflow.com/a/37001979/14335807.