我正在编写一个将标尺悬停在所有其他屏幕内容上的应用程序。我使用以下命令使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 )
我需要能够与根窗口的任何彩色部分移动/交互,但是需要能够单击任何透明部分...到目前为止,我只能完全抓住鼠标或完全错过它