I'm currently working on a schoolproject in Python, I and some friends try to code "Connect Four" and we have to use tkinter as GUI.
My current goal is to animate the falling coins. I read some articles about tkinter .after() method, but I'm not sure how to implement this properly into a single function (It should just loop a few times until the coin is on its final position)
the time.sleep method is not nice (freezes the gui, no animation showing), i know that :(
Here a simplified Code >> i also had a idea to use the after method and let the called function return something, but i have no clue how to do this.
Would be nice if somebody give a hint how to get this working
def addCoin(self, x):
#gets called when the button is pressed, x is the column
#seachest the highest(lowest on screen) free field >> the final field
maxdown = 0
#self.y >> fieldsize, maxdown is correct
while maxdown < self.y and self.getValue(x, maxdown) == 0:
maxdown +=1
#to get the last empty field, not the first full
maxdown -= 1
print(str(maxdown)+" is the next empty field")
if maxdown < 0:
print("you cant place a coin here")
return
#animation, which is my problem
animy = 0
while animy < maxdown:
#set field color to playercolor, wait , set field white, next field
self.setValue(x, animy, self.activeplayer.nr)
time.sleep(0.15)
self.setValue(x, animy, 0)
animy += 1
#After animation, check for win, works fine