Python Forum
Moving with objects in tkinter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Moving with objects in tkinter
#1
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.
Reply
#2
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))
Reply
#3
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 ?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter moving an class object with keybinds gr3yali3n 5 3,185 Feb-10-2021, 09:13 PM
Last Post: deanhystad
  [Tkinter] how to draw dynamic moving scale and potting trace point on waveform in tkinter pytho sameer_1985 0 2,002 May-31-2020, 01:52 PM
Last Post: sameer_1985

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020