Nachinka

turtle

Apr 22nd, 2021
643
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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()
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×