There is no way using pygame that I know of that will allow you to do this. You will instead have to use plain old-fashioned algebra.
You are going to be using the equation of the line that the squares are on. Ax, Ay, Bx, and By will be representing the coordinates of the different squares. All you have to do is get a y coordinate for an inputted x coordinate by using y=(Ay-By)/(Ax-Bx)*(x-Ax)+Ay
, or get an x coordinate for an inputted y coordinate by using x=(Ay-By)/(Ax-Bx)*(x-Ay)+Ax
. You will have to figure out which y or x coordinates to enter manually.
To find the distance between the squares, simply use the distance formula: math.sqrt((Ax-Bx)**2+(Ay-By)**2)