Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. # 4.9 This program displays information about a rectangle drawn by the user
  2. from graphics import *
  3. import math
  4.  
  5. def main():
  6. win = GraphWin('Rectangle Information', 400., 400)
  7. win.setCoords(0, 0, 10, 10)
  8.  
  9. # Get the x and y coordinate for Rectangle
  10. t1 = Text(Point(5, 9), 'First click to get the upper left corner').draw(win)
  11. ul = win.getMouse()
  12. t1.undraw()
  13.  
  14. t2 = Text(Point(5, 9), 'Second click to get the bottom right corner').draw(win)
  15. lr = win.getMouse()
  16. t2.undraw()
  17.  
  18. xul = int(ul.getX())
  19. yul = int(ul.getY())
  20. print(xul, yul)
  21. xlr = int(lr.getX())
  22. ylr = int(lr.getY())
  23.  
  24. print(xlr, ylr)
  25. rec = Rectangle(Point(xul, yul), Point(xlr, ylr))
  26. rec.draw(win)
  27.  
  28. # calculation of the area and perimeter
  29. area = abs((xul - xlr) * (yul - ylr))
  30. t3 = 'Area:', area
  31. Text(Point(5, 9), t3).draw(win)
  32. print(area)
  33.  
  34. l = abs(xul - xlr)
  35. w = abs(yul - ylr)
  36. perimeter = 2 * (l + w)
  37. t4 = 'Perimeter:', perimeter
  38. Text(Point(5, 8.5), t4).draw(win)
  39. print(perimeter)
  40.  
  41. win.getKey()
  42.  
  43. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement