如何在拖动面板时清空wxpython窗口内容?

2 投票
1 回答
1639 浏览
提问于 2025-04-15 20:22

我有三个面板,我想在它们上面拖动。 问题是,当我在一个面板上拖动时,会出现这样的情况: http://img41.yfrog.com/img41/9043/soundlog.png http://img41.yfrog.com/img41/9043/soundlog.png

我该如何刷新这个框架,以便在面板不再显示时能看到它的颜色呢?

这是我用来实现拖动的代码:

def onMouseMove(self, event):
    (self.pointWidth, self.pointHeight) = event.GetPosition()
    (self.width, self.height) = self.GetSizeTuple()
    if (self.pointWidth>100 and self.pointWidth<(self.width-100) and self.pointHeight < 15) or self.parent.dragging:
        self.SetCursor(wx.StockCursor(wx.CURSOR_SIZING))

        """implement dragging"""
        if not event.Dragging():
            self.w = 0
            self.h = 0
            return
        self.CaptureMouse()
        if self.w == 0 and self.h == 0:
            (self.w, self.h) = event.GetPosition()
        else:
            (posw, posh) = event.GetPosition()
            displacement = self.h - posh
            self.SetPosition( self.GetPosition() - (0, displacement))
    else:
        self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))

def onDraggingDown(self, event):
    if self.pointWidth>100 and self.pointWidth<(self.width-100) and self.pointHeight < 15:
        self.parent.dragging = 1
        self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
        self.SetBackgroundColour('BLUE')
        self.parent.SetTransparent(220)
        self.Refresh()

def onDraggingUp(self, event):
    self.parent.dragging = 0
    self.parent.SetTransparent(255)
    self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))

这些是与这些事件相关的绑定:

self.Bind(wx.EVT_MOTION, self.onMouseMove)
self.Bind(wx.EVT_LEFT_DOWN, self.onDraggingDown)
self.Bind(wx.EVT_LEFT_UP, self.onDraggingUp)

通过这个,如果我点击面板的顶部,然后向上或向下移动,面板的位置就会跟着鼠标的位置变化(我在拖动面板)。

1 个回答

1

为了在每次移动self的时候刷新父窗口,你可以在你的def onMouseMove方法中,现有的self.SetPosition调用后面加上

self.parent.Refresh()

现在你只是在def onDraggingDown方法中刷新窗口,也就是鼠标左键第一次点击并按住的时候,而不是在鼠标按住的情况下每次移动鼠标的时候(也就是“拖动”的动作本身)。

我无法下载你的代码进行测试,因为你选择上传的那个网站实在太“乱七八糟”了——网站一直给我发广告,下载的方式也不清楚,有时还抱怨不支持我的设备(我用的是Mac和Google Chrome,而那个网站有些地方却坚持要Windows和IE或Firefox……)等等。我相信你可以找到其他更好用的网站,帮助你的人会更方便!-)

撰写回答