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