Python Forum

Full Version: Moving with objects in tkinter
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all, can anybody tell me, how to find out if some object is currently located at specific coordinates? Let´s consider object1 at x=100,y=100 and I want to know, if object2 is located somewhere near to this object1, let´s say up to 50px. How to write it and what´s the syntax of this? I already know that I can change coordinates by canvas.coords(object, xy) or change some parameters of that object by canvas.itemconfig(object, parameters). Thanks a lot.
There are several ways to measure the distance between two points in the plane
def distA(x1, y1, x2, y2):
    return abs(x1 - x2) + abs(y1 - y2)

def distB(x1, y1, x2, y2):
    return ((x1 - x2)**2 + abs(y1 - y2)**2)**0.5

def distC(x1, y1, x2, y2):
    return max(abs(x1 - x2), abs(y1 - y2))
Well but I need to know how to write a coordinates for specific objects. Let´s say object1 is 100,50. How can I write this without specific numbers? Just something like object1_x ?