您可以使用模块的
SetWindowLong功能
win32gui。如果您想要透明的点击后进入窗口,则只能在
GWL_EXSTYLE我们的窗口中应用。因此,您需要Window的windowhandle。
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 windowslExStyle = win32gui.GetWindowLong(hwnd, win32con.GWL_EXSTYLE)lExStyle |= win32con.WS_EX_TRANSPARENT | win32con.WS_EX_LAYEREDwin32gui.SetWindowLong(hwnd, win32con.GWL_EXSTYLE , lExStyle )
如果您想通过winapi使用来更改窗口的透明度
SetLayeredWindowAttributes。
编辑:用于通过单击单击的始终处于顶部的透明窗口的叠加层的示例代码。它获取当前的桌面图像并创建透明的覆盖层,因此您可以欣赏桌面背景图像。
from win32api import GetSystemMetricsimport win32conimport win32guiimport wxdef scale_bitmap(bitmap, width, height): image = wx.ImageFromBitmap(bitmap) image = image.Scale(width, height, wx.IMAGE_QUALITY_HIGH) result = wx.BitmapFromImage(image) return resultapp = wx.App()trans = 50# create a window/frame, no parent, -1 is default ID# change the size of the frame to fit the backgound imagesframe1 = wx.frame(None, -1, "KEA", style=wx.CLIP_CHILDREN | wx.STAY_ON_TOP)# create the class instanceframe1.ShowFullScreen(True)image_file = win32gui.SystemParametersInfo(win32con.SPI_GETDESKWALLPAPER,0,0)bmp1 = wx.Image(image_file, wx.BITMAP_TYPE_ANY).ConvertToBitmap()bmp1 = scale_bitmap(bmp1,GetSystemMetrics(1)*1.5,GetSystemMetrics(1))bitmap1 = wx.StaticBitmap(frame1, -1, bmp1, (-100, 0))hwnd = frame1.GetHandle()extendedStyleSettings = win32gui.GetWindowLong(hwnd, win32con.GWL_EXSTYLE)win32gui.SetWindowLong(hwnd, win32con.GWL_EXSTYLE, extendedStyleSettings | win32con.WS_EX_LAYERED | win32con.WS_EX_TRANSPARENT)win32gui.SetLayeredWindowAttributes(hwnd, 0, 255, win32con.LWA_ALPHA)frame1.SetTransparent(trans)def onKeyDown(e): global trans key = e.GetKeyCode() if key==wx.WXK_UP: print trans trans+=10 if trans >255: trans = 255 elif key==wx.WXK_DOWN: print trans trans-=10 if trans < 0: trans = 0 try: win32gui.SetLayeredWindowAttributes(hwnd, 0, trans, win32con.LWA_ALPHA) except: passframe1.Bind(wx.EVT_KEY_DOWN, onKeyDown)app.MainLoop()
您可以使用向上/向下箭头键动态更改透明度。注意,窗口框架是用“ wx”创建的,但也应该与tkinter一起使用。
随意使用您喜欢的代码。



