two_canvases.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. """turtledemo.two_canvases
  2. Use TurtleScreen and RawTurtle to draw on two
  3. distinct canvases in a separate window. The
  4. new window must be separately closed in
  5. addition to pressing the STOP button.
  6. """
  7. from turtle import TurtleScreen, RawTurtle, TK
  8. def main():
  9. root = TK.Tk()
  10. cv1 = TK.Canvas(root, width=300, height=200, bg="#ddffff")
  11. cv2 = TK.Canvas(root, width=300, height=200, bg="#ffeeee")
  12. cv1.pack()
  13. cv2.pack()
  14. s1 = TurtleScreen(cv1)
  15. s1.bgcolor(0.85, 0.85, 1)
  16. s2 = TurtleScreen(cv2)
  17. s2.bgcolor(1, 0.85, 0.85)
  18. p = RawTurtle(s1)
  19. q = RawTurtle(s2)
  20. p.color("red", (1, 0.85, 0.85))
  21. p.width(3)
  22. q.color("blue", (0.85, 0.85, 1))
  23. q.width(3)
  24. for t in p,q:
  25. t.shape("turtle")
  26. t.lt(36)
  27. q.lt(180)
  28. for t in p, q:
  29. t.begin_fill()
  30. for i in range(5):
  31. for t in p, q:
  32. t.fd(50)
  33. t.lt(72)
  34. for t in p,q:
  35. t.end_fill()
  36. t.lt(54)
  37. t.pu()
  38. t.bk(50)
  39. return "EVENTLOOP"
  40. if __name__ == '__main__':
  41. main()
  42. TK.mainloop() # keep window open until user closes it