移动tkinter对象会留下幽灵痕迹

时间:2019-02-03 05:13:50

标签: python python-3.x animation tkinter

我尝试移动一堆物体。它们的位置由onMouseMove更新。将对象移动得更快一点,将留下清晰的鬼影痕迹。谁能建议一些避免鬼影的方法? 这是我的代码:

def onCanvasLeftMouseDown(self, event): 
    self.mIsCanvasLeftMouseDown = True
    self.mOnMouseDownX = event.x
    self.mOnMouseDownY = event.y

def onCanvasMouseMove(self, event):
    self.mMouseX = event.x
    self.mMouseY = event.y
    if (self.mIsCanvasLeftMouseDown):
        self.mMouseMoveLimiter = self.mMouseMoveLimiter + 1

        if (self.mMouseMoveLimiter > 10):  
            self.mMouseMoveLimiter = 0

            difX = self.mMouseX - self.mOnMouseDownX
            difY = self.mMouseY - self.mOnMouseDownY

            for panel in self.mPanelList:
                baseX = panel.initalX
                baseY = panel.initalY
                panel.x = baseX + difX
                panel.y = baseY + difY

def onCanvasLeftMouseUp(self, event):
    self.mIsCanvasLeftMouseDown = False

我也尝试过使用动画函数并在after之后调用“ after(1,self.animate)”。但是,情况变得更糟,因此我决定将动画代码留在onMouseMove中。

请注意,Panel对象实际上是具有3个canvas子级小部件的Tkinter TextMaster对象中canvas的父对象(Panel)是另一个很大的canvas,这也是我的背景。

仅此而已,这是Panel类代码的主要部分:

class TATDPanel:
    def __init__(self, master, node):
        self.mCanvas = Canvas(self.mMaster, width=self.mCanvasWidth, height=self.mCanvasHeight, bg='gray') 

        self.mFormTextBox = Text(self.mCanvas, width=self.mFormTextBoxWidth, height=self.mFormTextBoxHeight)
        self.mFormTextBox.tag_configure("center", justify='center')


        self.mUPosTextBox = Text(self.mCanvas, width=5, height=0.6)
        self.mUPosTextBox.tag_configure("center", justify='center')

        self.mIndexTextBox = Text(self.mCanvas, width=3, height=0.6)
        self.mIndexTextBox.tag_configure("center", justify='center')

更新01: 这是指向整个项目的保管箱链接,该链接仅可使用1天。 https://www.dropbox.com/s/yi9ja9zkqo9xcjy/Dependency%20Parsing.rar?dl=0

0 个答案:

没有答案