python 捕获鼠标点击事件_在Python中的wx.Frame外部捕获鼠标事件

In Python using wxPython, how can I set the transparency and size of a window based on the proximity of the mouse relative to the application's window, or frame?

Eg. similar to a hyperbolic zoom, or The Dock in MAC OS X? I am trying to achieve this effect with a png with transparency and a shaped window.

Any libraries or code snippets that do this would be great too. Thanks.

解决方案

Here's code to do it. Basically uses the approach mentioned by Infinity77. Tested on Windows. Works nicely!

import wx

MIN_ALPHA = 64

MAX_ALPHA = 255

class Frame(wx.Frame):

def __init__(self):

super(Frame, self).__init__(None)

self.alpha = MAX_ALPHA

self.SetTitle('Mouse Alpha')

self.on_timer()

def on_timer(self):

x, y, w, h = self.GetRect()

mx, my = wx.GetMousePosition()

d1 = max(x - mx, mx - (x + w))

d2 = max(y - my, my - (y + h))

alpha = MAX_ALPHA - max(d1, d2)

alpha = max(alpha, MIN_ALPHA)

alpha = min(alpha, MAX_ALPHA)

if alpha != self.alpha:

self.SetTransparent(alpha)

self.alpha = alpha

wx.CallLater(20, self.on_timer)

if __name__ == '__main__':

app = wx.App(None)

frame = Frame()

frame.Show()

app.MainLoop()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值