栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Tkinter透视窗口不受鼠标单击的影响

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Tkinter透视窗口不受鼠标单击的影响

您可以使用模块的

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一起使用。

随意使用您喜欢的代码。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/634013.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号