Reputation: 326
I want to get an output when plansquare
is overlapping a new plansquare
(they are being created every millisecond), but I'm not sure how to do it.
So far, I check the coordinates of the new plansquare
, and what I want to happen is for it to check if it is touching any other plansquare
, and if so it will execute canvas.delete(plansquare)
.
def planwallfunc(event):
press = True
print(press)
x, y = event.x, event.y
def create_rectangles():
global x
global y
global plansquare
x, y = event.x, event.y
plansquare = canvas.create_image(x, y, image=planwall)
plansquarecoords = canvas.coords(plansquare)
if canvas.find_overlapping(plansquarecoords):
canvas.delete(plansquare)
else:
plansquare = canvas.create_image(x, y, image=planwall)
root.after(1, create_rectangles)
My error is TypeError: find_overlapping() missing 3 required positional arguments: 'y1', 'x2', and 'y2'
which means it is interpreting plansquarecoords
as x1. I instead want it to interpret it as all 4 - x1, y1, x2, y2 but I'm not sure what to do.
Anyone know?
Upvotes: 0
Views: 24
Reputation: 386210
The method requires four positional arguments but you're giving it one argument with four values.
The simplest solution is to use the *
operator to expand the list of four coordinates into four separate parameters:
canvas.find_overlapping(*plansquarecoords)
Upvotes: 1