Example done on 2/9 lecture


# draw a line segment
# and find its midpoint

from graphics import *

def main():

    win = GraphWin("Lines", 400, 500)
    print("click 2 points")
    p1 = win.getMouse()
    p2 = win.getMouse() 
    lineseg = Line(p1, p2)
    lineseg.draw(win)

    x1 = p1.getX()
    y1 = p1.getY()
    x2 = p2.getX()
    y2 = p2.getY()
    print(x1, y1, x2, y2)
    midx = (x1 + x2)/2
    midy = (y1 + y2)/2
    pc = Point(midx, midy)
    circ = Circle (pc, 5)
    circ.setFill("red")
    circ.draw(win)

    print("Click to close")
    win.getMouse()
    win.close()

main()