I am creating a Full Screen Desktop Overlay. On the Overlay, I am placing a PNG Image with Transparency. The Image should be 100% visible, but the Background should be completely Transparent. I should be able to clickthrough the Image, and the Transparent areas of the Image/Full screen Overlay.
I have successfully completed both tasks with slightly varying Code. But I am unable to combine the Tasks.
Here is the Original Question containing both sets of Code, and the Effects obtained.
Thank You for your time!! Tkinter: Cursor Active on Window Beneath Tkinter Only
import win32gui
import win32con
import win32api
import tkinter as tk
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()