この関数は Tying からコピーされ、TkInter で非対話型 (クリックスルー) オーバーレイを設定します
ウィンドウをクリックできないだけでなく、png も透明ではありません。PNG はこちら: https://drive.google.com/file/d/1tlLl2hjPq38mc_c_PpMhkKDlP1HqvDY5/view
ウィンドウは次のようになります。
私は何が欠けていますか?
from tkinter import*
import win32gui
from win32gui import GetForegroundWindow, ShowWindow, FindWindow, SetWindowLong, GetWindowLong, SetLayeredWindowAttributes
from win32con import SW_MINIMIZE, WS_EX_LAYERED, WS_EX_TRANSPARENT, GWL_EXSTYLE
def setClickthrough(hwnd):
try:
styles = GetWindowLong(hwnd, GWL_EXSTYLE)
styles |= WS_EX_LAYERED | WS_EX_TRANSPARENT
SetWindowLong(hwnd, GWL_EXSTYLE, styles)
SetLayeredWindowAttributes(hwnd, 0, 255, win32con.LWA_ALPHA)
except Exception as e:
print(e)
root = Tk()
root.geometry("100x100")
root.overrideredirect(1)
root.attributes('-topmost', 1)
pic = PhotoImage(file=r'on2.png')
root.wm_attributes("-transparentcolor", 'white')
boardbutton = Label(root, image=pic, bd=0,
bg='white')
boardbutton.pack()
setClickthrough(root.winfo_id())
root.mainloop()