如何解决在 wxpython 中检测拖动
顾名思义,我试图在 wxpython 中运行一个函数,该函数在鼠标点击和拖动时激活并能够检测到拖动方向。从我的研究中我看到它是一个 wx.MouseEvent,但我没有找到任何实际的例子来帮助我理解如何使用它。有人可以帮忙吗?
解决方法
这是一个简单的例子:
import wx
class MyFrame(wx.Frame):
def __init__(self):
super().__init__(None,-1,pos=(300,150),size=(320,250))
self.panel = wx.Panel(self)
self.text = wx.StaticText(self.panel,label="Left click mouse,move and release")
self.panel.Bind(wx.EVT_LEFT_DOWN,self.OnDown)
self.panel.Bind(wx.EVT_LEFT_UP,self.OnUp)
self.panel.Bind(wx.EVT_MOTION,self.OnDrag)
self.Show()
def OnDown(self,event):
x,y = event.GetPosition()
print("Click coordinates: X=",x," Y=",y)
def OnUp(self,y = event.GetPosition()
print("Release coordinates: X=",y)
def OnDrag(self,y = event.GetPosition()
if not event.Dragging():
event.Skip()
return
event.Skip()
#obj = event.GetEventObject()
#sx,sy = obj.GetScreenPosition()
#self.Move(sx+x,sy+y)
print("Dragging position",y)
app = wx.App()
window = MyFrame()
app.MainLoop()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。