Once again I am stucked.
In a canvas I display 9 images Every 8 rows I add a column. This is only for testing purposes. At the end the images should be hundreds. I am trying to identify each image with a unique number. In order to do this I have an event which gives me the coordinates of the canvas. And here comes the noobs part. To get this unique number my code is
if x_on_grid==0 and y_on_grid==448:
index_bin=0
elif x_on_grid==0 and y_on_grid==384:
index_bin=1
elif x_on_grid==0 and y_on_grid==320:
index_bin=2
elif x_on_grid==0 and y_on_grid==256:
index_bin=3
elif x_on_grid==0 and y_on_grid==192:
index_bin=4
elif x_on_grid==0 and y_on_grid==128:
index_bin=5
elif x_on_grid==0 and y_on_grid==64:
index_bin=6
elif x_on_grid==0 and y_on_grid==0:
index_bin=7
elif x_on_grid==64 and y_on_grid==448: #new column
index_bin=8
elif x_on_grid==64 and y_on_grid==384:
index_bin=9
Of course it works perfectly, but it's not scientific at all. I am trying to reduce all these lines with a loop but I can't get the number needed, only the last one.
Any ideas?
Best
canvas.create_stuffreturns an id. so basically sayimage1 = canvas.create_image(*args, **kwargs)will result inimage1being an integer for example 1 so there is no need to do what You are doingindex_bin = (448 - y_on_grid) // 64 + 8 * (x_on_grid // 64)- you might want to replace some constants by variables to accomodate more images.image-001. When the user clicks, use the canvasfind_closestmethod to determine which object you clicked on and get the object's tag to find out what it's index is.