You can do this, using undraw()
method. Change your __init__
to:
def __init__(self):
self.win = GraphWin('Demo2', 800, 600) # give title and dimensions
self.th = threading.Thread(target=self.FlashThread)
self.correctMessage = Text(Point(self.win.getWidth()/2, 20), 'Correct!')
self.incorrectMessage = Text(Point(self.win.getWidth()/2, 20), 'Incorrect,Try Again')
and flash
to
def flash(self, count):
try:
self.correctMessage.undraw()
self.incorrectMessage.undraw()
diameter = 50
centers = ((55,55), (170,55), (285,55), (55,170), (170,170),
(285,170), (55,285), (170,285), (285,285))
circles = list()
for point in centers:
c = Circle(Point(point[0], point[1]), diameter)
circles.append(c)
c.setFill("blue")
c.draw(self.win)
circles[count].setFill("yellow")
mouseClick = self.win.getMouse()
leftX = centers[count][0] - diameter
rightX = centers[count][0] + diameter
upperY = centers[count][1] - diameter
lowerY = centers[count][1] + diameter
if (upperY < mouseClick.y < lowerY) and (leftX < mouseClick.x < rightX):
self.correctMessage.draw(self.win)
else:
self.incorrectMessage.draw(self.win)
except:
self.win.exit(0)