我正在创建一个全屏覆盖。 如果你用谷歌搜索“Twitch Overlay”,你就会明白它会是什么样子。
每当我的鼠标位于
tkinter
图像顶部时。
我无法单击它下面的窗口。
import tkinter as tk
root = tk.Tk()
#root.geometry('')
root.overrideredirect(True)
root.config(bg="blue")
root.attributes("-transparentcolor", "blue",'-topmost','true')
#root.lift()
#root.wm_attributes('-disabled',True)
canvas = tk.Canvas(root, bg="blue")
canvas.configure(width = 1280, height = 720)
canvas.grid()
tk_img = tk.PhotoImage(file="1.png")
canvas.create_image(0, 0, image=tk_img, anchor="nw")
root.mainloop()
我尝试使用
cursor='none'
,当我将鼠标悬停在图像上时,它确实会使光标不可见。
但下面的窗口不可点击。
import win32gui
import win32con
import win32api
def set_clickthrough(hwnd, root):
# Get window style and perform a 'bitwise or' operation to make the style layered and transparent, achieving
# the clickthrough property
l_ex_style = win32gui.GetWindowLong(hwnd, win32con.GWL_EXSTYLE)
l_ex_style |= win32con.WS_EX_TRANSPARENT | win32con.WS_EX_LAYERED
win32gui.SetWindowLong(hwnd, win32con.GWL_EXSTYLE, l_ex_style)
# Set the window to be transparent and appear always on top
win32gui.SetLayeredWindowAttributes(hwnd, win32api.RGB(0, 0, 0), 100, win32con.LWA_ALPHA) # transparent
win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, root.winfo_x(), root.winfo_y(), root.winfo_width(), root.winfo_height(), 0)
root = tk.Tk()
root.overrideredirect(True)
root.attributes("-transparentcolor", "white",'-topmost',1)
root.config(bg="white")
canvas = tk.Canvas(root, bg = 'white')
canvas.configure(width = 1280, height = 720)
canvas.grid()
set_clickthrough(canvas.winfo_id(),root)
tk_img = tk.PhotoImage(file="1.png")
canvas.create_image(0, 0, image=tk_img, anchor="nw")
canvas.pack()
root.mainloop()
https://i.imgur.com/vCNoQox.png
我已经实现了让下面的屏幕可点击的目标,但它在所有内容上覆盖了一层透明的白色。