blob: 26882caccf72c3231c426f5107b58909b0be39b7 [file] [log] [blame]
Terry Jan Reedyc5a72e62014-06-24 22:21:41 -04001"""turtledemo.two_canvases
2
3Use TurtleScreen and RawTurtle to draw on two
4distinct canvases.
Martin v. Löwis97cf99f2008-06-10 04:44:07 +00005"""
Terry Jan Reedyc5a72e62014-06-24 22:21:41 -04006#The final mainloop only serves to keep the window open.
7
8#TODO: This runs in its own two-canvas window when selected in the
9#demoviewer examples menu but the text is not loaded and the previous
10#example is left visible. If the ending mainloop is removed, the text
11#Eis loaded, this run again in a third window, and if start is pressed,
12#demoviewer raises an error because main is not found, and then freezes.
13
Martin v. Löwis60ebb8b2008-09-21 07:32:10 +000014from turtle import TurtleScreen, RawTurtle, TK
Martin v. Löwis97cf99f2008-06-10 04:44:07 +000015
16root = TK.Tk()
17cv1 = TK.Canvas(root, width=300, height=200, bg="#ddffff")
18cv2 = TK.Canvas(root, width=300, height=200, bg="#ffeeee")
19cv1.pack()
20cv2.pack()
21
22s1 = TurtleScreen(cv1)
23s1.bgcolor(0.85, 0.85, 1)
24s2 = TurtleScreen(cv2)
25s2.bgcolor(1, 0.85, 0.85)
26
27p = RawTurtle(s1)
28q = RawTurtle(s2)
29
30p.color("red", (1, 0.85, 0.85))
31p.width(3)
32q.color("blue", (0.85, 0.85, 1))
33q.width(3)
34
35for t in p,q:
36 t.shape("turtle")
37 t.lt(36)
38
39q.lt(180)
40
41for t in p, q:
42 t.begin_fill()
43for i in range(5):
44 for t in p, q:
45 t.fd(50)
46 t.lt(72)
47for t in p,q:
48 t.end_fill()
49 t.lt(54)
50 t.pu()
51 t.bk(50)
52
53## Want to get some info?
54
Alexander Belopolskyea13d9d2010-11-01 17:39:37 +000055#print(s1, s2)
56#print(p, q)
57#print(s1.turtles())
58#print(s2.turtles())
Martin v. Löwis97cf99f2008-06-10 04:44:07 +000059
60TK.mainloop()