[Python] GUI on top of all windows in windows that does not interfere with clicking on other...

Discussão em 'Python' iniciado por Stack, Maio 7, 2025.

  1. Stack

    Stack Membro Participativo

    A difficult task has arisen, let's imagine a situation, I have a computer game and I want to let's say... draw your cursor using python, or some shapes. It doesn't matter why I need it, I just need it and that's it =) The first thing I tried to use was Tkinter. The plan was to create a transparent gui window on top of the game window, in which I would use create_rectangle to draw the shapes I needed, but as I understand it, Tkinter does not know how to make windows transparent, because if you use attributes("-fullscreen", True, '-alpha', 0), then all the shapes also become transparent.. Moreover, I'm not sure if the gui has the ability to make a window in such a way that it does not interfere with clicks in the game window, i.e. in other words, is it possible to make the clicks go "through" the python GUI window. Therefore, I had another idea, using win32gui to draw pixels directly on the screen, but this method also did not suit me because it is an extremely slow process and even drawing 1 pixel in an endless loop makes windows slow down, not to mention that the pixel is constantly disappearing because of the game image on the screen updated.

    Please tell me if it is possible to create a transparent window with the ability to display shapes on it through any gui libraries for python, and even so that this window does not interfere with mouse and keyboard clicks on the game or other programs, it does not matter. In other words, so that it is transparent both visually and for clicks. at the same time, it was on top of other windows.

    from tkinter import *


    root = Tk()
    root.title("METANIT.COM")
    root.attributes("-fullscreen", True, '-alpha', 0.3) #на весь экрн root


    canvas = Canvas(root, bg='white', highlightthickness=0)
    canvas.pack(fill=BOTH, expand=True) #canvas на весь root


    root_width = root.winfo_screenwidth() #Ширина окна
    root_height = root.winfo_screenheight() #Высота окна


    center_root_width = root.winfo_screenwidth()/2 #Центр ширины
    center_root_height = root.winfo_screenheight()/2 #Центр высоты

    size = 2 # размер области для лучшей видимости

    canvas.create_rectangle(center_root_width-size,center_root_height-size,center_root_width+size,center_root_height+size,outline='red') #Нарисовать пиксель в центре экрана



    canvas.pack(anchor=CENTER, expand=1)
    root.mainloop()


    (If you set alpha = 0, not only the window becomes transparent, but also the elements on the window. There will also be problems with the python window interfering with clicking on the game window.)

    and

    import win32gui
    import win32api

    width = 1920
    height = 1080

    x = width/2
    y = height/2


    while True:

    dc = win32gui.GetDC(0)
    red = win32api.RGB(255, 0, 0)

    win32gui.SetPixel(dc, int(x), int(y), red) # draw red at 0,0


    (Slows down, flashes in the game, disappears)

    I don't know how, and I don't want to interfere in any way with the game process, otherwise I risk getting banned. I just want to draw on my screen so that this image is displayed on top of the game window without interfering with my playing.

    Continue reading...

Compartilhe esta Página