-2

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)
cdlane
  • 40,441
  • 5
  • 32
  • 81
Antonio
  • 101
  • 8

2 Answers2

0

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)
Antonio
  • 101
  • 8
0

It might be nice to give your user feedback as to where they placed their first point as they're placing their second one:

from graphics import *

def drawLine(window):

    pt1 = window.getMouse()
    pt1.draw(window)

    pt2 = window.getMouse()

    line = Line(pt1, pt2)
    line.setOutline("black")
    line.draw(window)

    pt1.undraw()

win = GraphWin("Window", 250, 250)

drawLine(win)

win.getMouse()
win.close()
cdlane
  • 40,441
  • 5
  • 32
  • 81