Search code examples
pythonzelle-graphics

Invoke Python Zelle graphics drawLine() via interactively mousing points


https://www.cs.swarthmore.edu/~newhall/cs21/pythondocs/using-graphics.html

I'm trying to create a Python Zelle graphics function that will allow the user to use the mouse to click two points of his/her choice to draw a line. This is what I have so far:

def drawLine():
    win = GraphWin("Window", 250, 250)

    p = win.getMouse()
    line = Line((p.getX, p.getY), (p.getX, p.getY))
    line.setOutline("black")
    line.draw(win)

Solution

  • Solved it so thought I should post the code.

    def drawLine():
        win = GraphWin("Window", 250, 250)
    
        p = win.getMouse()
        p2 = win.getMouse()
    
        line = Line(Point(p.getX(), p.getY()), Point(p2.getX(), p2.getY()))
        line.setOutline("black")
        line.draw(win)