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()
總結
以上是生活随笔為你收集整理的python 捕获鼠标点击事件,在Python中的wx.Frame外部捕获鼠标事件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux bash and,linux
- 下一篇: 计算机网络工程应用,全面信息化管理在计算