Tkinter透视窗口不受鼠标单击的影响 [英] Tkinter see through window not affected by mouse clicks
问题描述
我目前正在通过发送鼠标和击键命令来使用python控制游戏.我要做的是在游戏上方放置一个透明的Tkinter窗口,以提供一些信息,例如鼠标位置和像素颜色.
I am currently controlling a game with python by sending mouse and keystroke commands. What I am looking to do is have a transparent Tkinter window lay overtop of the game to provide some information such as mouse location and pixel color.
我熟悉如何更改窗口的alpha属性以使其透明,但不知道如何始终将窗口置于前面并让鼠标单击通过.
I am familiar with changing the window's alpha attribute to make it transparent but have no idea how to always keep that window in front and have mouse clicks pass through it.
我目前控制游戏的方法包括在某些位置截取屏幕截图并分析颜色内容.我还需要一些方法来做到这一点,而不会干扰Tkinter窗口.
My current method of controlling the game involves taking screenshots in certain locations and analyzing the color content. I will also need some way to do this without the Tkinter window interfering.
Pyscreenshot用于屏幕截图 win32api用于单击
Pyscreenshot is used for screenshots win32api is used for clicking
谢谢你, 亚历克
推荐答案
,您可以使用win32gui
模块的SetWindowLong
功能.如果您想要透明的点击后进入窗口,则仅在我们的窗口中应用GWL_EXSTYLE
.因此,您需要Window的windowhandle.
you can use the SetWindowLong
function of win32gui
module. If you want a transparent click through window you have to apply GWL_EXSTYLE
's ony our window. Therefore you need the windowhandle of your Window.
hwnd = win32gui.FindWindow(None, "Your window title") # 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 )
如果要通过winapi更改窗口的透明度,请使用SetLayeredWindowAttributes
.
If you want to change the transparency of your window via winapi use SetLayeredWindowAttributes
.
这篇关于Tkinter透视窗口不受鼠标单击的影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!