Nachinka

turtle

Apr 22nd, 2021
852
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. import turtle
  2. import tkinter as tk
  3.  
  4. def forward():
  5.     t.forward(100)
  6.  
  7. def back():
  8.     t.back(100)
  9.  
  10. def left():
  11.     t.left(90)
  12.  
  13. def right():
  14.     t.right(90)
  15.  
  16. root = tk.Tk()
  17. canvas = tk.Canvas(master = root, width = 500, height = 500)
  18. canvas.pack()
  19.  
  20. t = turtle.RawTurtle(canvas)
  21. t.pencolor("#ff0000") # Red
  22. ts = t.getscreen()
  23. ts.addshape(r"d:\Downloads\rabbit.gif")
  24.  
  25. shape =((0, 0), (10, 10), (20, 0), (10, -10))
  26. # registering the new shape
  27. ts.register_shape('diamond', shape)
  28. #t.shape("diamond")
  29.  
  30. print(ts.getshapes())
  31. #t.shape("d:\\Downloads\\rabbit.gif")
  32.  
  33. t.penup()   # Regarding one of the comments
  34. t.pendown() # Regarding one of the comments
  35.  
  36. tk.Button(master = root, text = "Forward", command = forward).pack(side = tk.LEFT)
  37. tk.Button(master = root, text = "Back", command = back).pack(side = tk.LEFT)
  38. tk.Button(master = root, text = "Left", command = left).pack(side = tk.LEFT)
  39. tk.Button(master = root, text = "Right", command = right).pack(side = tk.LEFT)
  40.  
  41. root.mainloop()
Add Comment
Please, Sign In to add comment