blob: 105a06b6119a032b00f39926c8f5ca728739f455 [file] [log] [blame]
Benjamin Peterson9cf41d02010-03-11 22:33:25 +00001#!/usr/bin/env python
Martin v. Löwis87184592008-06-04 06:29:55 +00002""" turtle-example-suite:
3
4 tdemo_paint.py
5
Terry Jan Reedy3fecd482014-06-24 22:21:36 -04006A simple event-driven paint program
Martin v. Löwis87184592008-06-04 06:29:55 +00007
Terry Jan Reedy3fecd482014-06-24 22:21:36 -04008- left mouse button moves turtle
9- middle mouse button changes color
10- right mouse button toogles betweem pen up
11(no line drawn when the turtle moves) and
12pen down (line is drawn). If pen up follows
13at least two pen-down moves, the polygon that
14includes the starting point is filled.
Martin v. Löwis87184592008-06-04 06:29:55 +000015 -------------------------------------------
16 Play around by clicking into the canvas
17 using all three mouse buttons.
18 -------------------------------------------
19 To exit press STOP button
20 -------------------------------------------
21"""
22from turtle import *
23
24def switchupdown(x=0, y=0):
25 if pen()["pendown"]:
26 end_fill()
27 up()
28 else:
29 down()
30 begin_fill()
31
32def changecolor(x=0, y=0):
33 global colors
34 colors = colors[1:]+colors[:1]
35 color(colors[0])
36
37def main():
38 global colors
39 shape("circle")
40 resizemode("user")
41 shapesize(.5)
42 width(3)
43 colors=["red", "green", "blue", "yellow"]
44 color(colors[0])
45 switchupdown()
46 onscreenclick(goto,1)
47 onscreenclick(changecolor,2)
48 onscreenclick(switchupdown,3)
49 return "EVENTLOOP"
50
51if __name__ == "__main__":
52 msg = main()
53 print msg
54 mainloop()