I have been assigned the same homework task as a previous poster (Fo.katia): create a program that draws a rectangle with two mouse clicks. I had modified the code in my textbook as the previous poster did with the same results. I saw a reply to the other post that said "There is a line missing somewhere, such as 1. win = GraphWin("My Rectangle", 300, 300)". I tried adding this to my code
win = GraphWin("Draw a Rectangle", 100, 100)
but I still only got a line. I can see the logic in this statement but cannot figure out how to actually make this work. Here is my code:
# rectangle.pyw
from graphics import *
def main():
win = GraphWin("Draw a Rectangle", 100, 100)
win.setCoords(0.0, 0.0, 10.0, 10.0)
message = Text(Point(5, 0.5), "Click on two points")
message.draw(win)
# Get and draw a rectangle
p1 = win.getMouse()
p1.draw(win)
p2 = win.getMouse()
p2.draw(win)
p3 = win.getMouse()
p3.draw(win)
p4 = win.getMouse()
p4.draw(win)
# Use Polygon object to draw a rectangle
rectangle = Polygon(p1,p2,p3,p4)
rectangle.setFill("purple")
rectangle.setOutline("black")
rectangle.draw(win)
# Wait for another click to exit
message.setText("Click anywhere to quit.")
win.getMouse()
main()
Any assistance with this would be greatly appreciated.