Python Forum
Moving with objects in tkinter - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: Moving with objects in tkinter (/thread-14742.html)



Moving with objects in tkinter - dan789 - Dec-14-2018

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.


RE: Moving with objects in tkinter - Gribouillis - Dec-15-2018

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))



RE: Moving with objects in tkinter - dan789 - Dec-15-2018

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 ?