| Benjamin Peterson | 9cf41d0 | 2010-03-11 22:33:25 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python | 
| Martin v. Löwis | 8718459 | 2008-06-04 06:29:55 +0000 | [diff] [blame] | 2 | """       turtle-example-suite: | 
 | 3 |  | 
 | 4 |             tdemo_paint.py | 
 | 5 |  | 
| Terry Jan Reedy | 3fecd48 | 2014-06-24 22:21:36 -0400 | [diff] [blame] | 6 | A simple  event-driven paint program | 
| Martin v. Löwis | 8718459 | 2008-06-04 06:29:55 +0000 | [diff] [blame] | 7 |  | 
| Terry Jan Reedy | 3fecd48 | 2014-06-24 22:21:36 -0400 | [diff] [blame] | 8 | - 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 | 
 | 12 | pen down (line is drawn). If pen up follows | 
 | 13 | at least two pen-down moves, the polygon that | 
 | 14 | includes the starting point is filled. | 
| Martin v. Löwis | 8718459 | 2008-06-04 06:29:55 +0000 | [diff] [blame] | 15 |  ------------------------------------------- | 
 | 16 |  Play around by clicking into the canvas | 
 | 17 |  using all three mouse buttons. | 
 | 18 |  ------------------------------------------- | 
 | 19 |           To exit press STOP button | 
 | 20 |  ------------------------------------------- | 
 | 21 | """ | 
 | 22 | from turtle import * | 
 | 23 |  | 
 | 24 | def switchupdown(x=0, y=0): | 
 | 25 |     if pen()["pendown"]: | 
 | 26 |         end_fill() | 
 | 27 |         up() | 
 | 28 |     else: | 
 | 29 |         down() | 
 | 30 |         begin_fill() | 
 | 31 |  | 
 | 32 | def changecolor(x=0, y=0): | 
 | 33 |     global colors | 
 | 34 |     colors = colors[1:]+colors[:1] | 
 | 35 |     color(colors[0]) | 
 | 36 |  | 
 | 37 | def 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 |  | 
 | 51 | if __name__ == "__main__": | 
 | 52 |     msg = main() | 
 | 53 |     print msg | 
 | 54 |     mainloop() |