Advertisement
furas

Python - graphics - example

May 28th, 2017
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. from graphics import *
  2.  
  3. x1 = 20
  4. y1 = 30
  5.  
  6. x2 = 180
  7. y2 = 165
  8.  
  9. w = GraphWin("Graphics Window", 400, 400)
  10.  
  11. line = Line(Point(x1, y1), Point(x2, y2))
  12. line.draw(w)
  13.  
  14. dx = x2 - x1
  15. dy = y2 - y1
  16. #slope = dx/dy # if dy is zero then it gives ERROR
  17. length = (dx**2 + dy**2)**0.5
  18. print(length)
  19.  
  20. txt = Text(Point(200, 200), str(length))
  21. txt.draw(w)          
  22.  
  23. p = Point(50, 60)
  24. p.getX()
  25. p.getY()
  26.  
  27. w.getMouse() # wait on mouse click
  28. w.close() # close window
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement