部分点击通过((仅限Windows)

2024-06-28 19:35:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在编写一个应用程序,将标尺悬停在所有其他屏幕内容上。我使用以下方法使tkinter窗口和相关画布透明:

root.overrideredirect(True) #This hides the window outline/controls 
root.state('zoomed') #This scales the window to fill the page
root.configure(background=bgColor) #Set bg color of window (used to make transparent \/)
root.wm_attributes("-transparentcolor", bgColor) #Necessary for transparent, window
root.lift()#Lifting window above all others
root.wm_attributes("-topmost", True)#Hold window on top of all other windows

我能够通过这个应用程序点击透明的地方,然后用pyinstaller编译成exe。但是,在编译成exe之后,这就不可能了

我尝试了在这里共享的解决方案:Tkinter see through window not affected by mouse clicks 然而,这使得整个窗口可以点击通过,这意味着我不能再与顶部窗口的非透明部分进行交互(我必须能够这样做)

hwnd = win32gui.FindWindow(None, "Digital Ruler") # Getting window handle
# hwnd = root.winfo_id() getting hwnd with Tkinter windows
# hwnd = root.GetHandle() getting hwnd with wx windows
lExStyle = win32gui.GetWindowLong(hwnd, win32con.GWL_EXSTYLE)
lExStyle |=  win32con.WS_EX_TRANSPARENT | win32con.WS_EX_LAYERED 
win32gui.SetWindowLong(hwnd, win32con.GWL_EXSTYLE , lExStyle )

我需要能够移动/与根窗口的任何彩色部分互动,但需要能够通过任何透明部分点击。。。到目前为止,我只能完全抓住老鼠或完全错过它


Tags: ofthetotrue应用程序windowsrootwindow