How to make a moving circle delete on impact with another circle in Python
<pre><code>from tkinter import *
import time
root = Tk()
canvas =Canvas(root, width=1000, height=1000, bg= '#2B2B2B')
canvas.pack()

#id1 white
x = 400
y = 400
r = 50

#rc2 orange
f = 100
d = 400
r2 =100



id1 = canvas.create_oval(x - r, y - r, x + r, y + r, outline='white')


id2 = canvas.create_oval(f - r2, d - r2, f + r2, d + r2, outline='#CC7832')



def move_circle():
    for k in range(31):


        time.sleep(0.025)

        canvas.move(id2, 5, 0)
        canvas.update()

def get_coords(id_num):

    pos = canvas.coords(id_num)
    x = (pos[0] + pos[2])/2
    y = (pos[1] + pos[3])/2

    print(x, y)
    return x, y


from math import sqrt


def distance(id1, id2):
    x1, y1 = get_coords(id1)
    x2, y2 = get_coords(id2)
    print("distance", x1, y1, x2, y2)
    return sqrt((x2 - x1)**2 + (y2 - y1)**2)

def delete_circle():   #12
    if distance(id1, id2) &lt; (r+r2):
        canvas.delete(id2)

move_circle()
delete_circle()
root.mainloop()
</code></pre>

<p>'''Hi Guys, I am trying to get circle id2 to delete when it hits id1. At the moment this only works if I have my range
set to between 31-89 in the move circle function. I understand that the reason this is the case is because the delete function only executes when the move circle function has completed it's loop. I think the solution is to somehow get the delete function to have access to the coordinate changes as they occur during the loop. However I have hit a wall to say the least on trying to do this. Any help would be much appreciated. Thanks a million in advance.</p>

<p>You just need find_overlapping method.</p>

<p>Basic example :</p>

<pre><code>id1 = canvas.create_oval(x - r, y - r, x + r, y + r, outline='white')
id2 = canvas.create_oval(f - r2, d - r2, f + r2, d + r2, outline='#CC7832')

id1_coords = canvas.coords(id1)

def move_circle(x, y):
    canvas.move(id2, x, y)
    if id2 not in canvas.find_overlapping(*id1_coords) :
        canvas.after(100, move_circle, x, y)
    else :
        canvas.delete(id2)

move_circle(5, 0)

root.mainloop()
</code></pre>

python tkinter