小编Ton*_* Qu的帖子

点击式 tkinter 窗口

该函数是从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()
Run Code Online (Sandbox Code Playgroud)

python window tkinter click-through transparent

4
推荐指数
1
解决办法
2882
查看次数

标签 统计

click-through ×1

python ×1

tkinter ×1

transparent ×1

window ×1