Advertisement
skip420

LineDrawing

Mar 8th, 2022
902
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. #Draw Lines
  2.  
  3.  
  4.  
  5. # python program
  6. # import for turtle module
  7. import turtle
  8.  
  9. # defining instance of turtle
  10. pen=turtle.Turtle()
  11. head=turtle.Turtle()
  12. head.penup()
  13. head.hideturtle()
  14. head.goto(0, 260)
  15. head.write("This is to display the coordinates of the position where mouse is clicked",
  16.            align = "center",
  17.            font = ("courier", 12, "normal"))
  18.  
  19. # giving circle shape to pen i.e. instance of turtle
  20. pen.shape("circle")
  21.  
  22. # giving colour to turtle
  23. pen.color("red")
  24.  
  25. # define function to make the turtle move
  26. # to the position which is clicked by the mouse
  27. def btnclick(x, y):
  28.     pen.goto(x, y)
  29.     head.clear()    
  30.     head.write(f"x coordinate = {x}, y coordinate = {y}",
  31.                align = "center", font = ("courier", 24, "normal"))
  32.      
  33. # this function will call btnclick whenever mouse is clicked    
  34. turtle.onscreenclick(btnclick, 1)
  35. turtle.listen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement