wxpython 窗口内可移动控件

来源:互联网 发布:淘宝网中老年秋装外套 编辑:程序博客网 时间:2024/05/07 13:29
import wxapp = wx.App(False)d = {}def wMouseDown(e):    print "!!!", e.GetEventObject()def MouseDown(e):       o           = e.GetEventObject()    sx,sy       = panel.ScreenToClient(o.GetPositionTuple())    dx,dy       = panel.ScreenToClient(wx.GetMousePosition())    o._x,o._y   = (sx-dx, sy-dy)    d['d'] = odef MouseMove(e):    try:        if 'd' in d:            o = d['d']            x, y = wx.GetMousePosition()            o.SetPosition(wx.Point(x+o._x,y+o._y))    except: passdef MouseUp(e):    try:        if 'd' in d: del d['d']    except: passframe = wx.Frame(None, -1, 'simple.py')panel = wx.Panel(frame)box = wx.BoxSizer(wx.VERTICAL)button1 = wx.Button(panel, -1, "foo")box.Add(button1, 0, wx.ALL, 10)button2 = wx.Button(panel, -1, "bar")box.Add(button2, 0, wx.ALL, 10)button1.Bind(wx.EVT_LEFT_DOWN, MouseDown)button2.Bind(wx.EVT_LEFT_DOWN, MouseDown)button1.Bind(wx.EVT_MOTION, MouseMove)button2.Bind(wx.EVT_MOTION, MouseMove)button1.Bind(wx.EVT_LEFT_UP, MouseUp)button2.Bind(wx.EVT_LEFT_UP, MouseUp)panel.Bind(wx.EVT_MOTION, MouseMove)panel.Bind(wx.EVT_LEFT_UP, MouseUp)panel.SetSizer(box)panel.Layout()frame.Show()app.MainLoop()

0 0
原创粉丝点击