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