blob: dde16912dfed8a757dd97475912ab2286edaa6f3 [file] [log] [blame]
Benjamin Peterson90f5ba52010-03-11 22:53:45 +00001#!/usr/bin/env python3
Martin v. Löwis97cf99f2008-06-10 04:44:07 +00002""" turtle-example-suite:
3
4 tdemo_paint.py
5
Terry Jan Reedyc5a72e62014-06-24 22:21:41 -04006A simple event-driven paint program
Martin v. Löwis97cf99f2008-06-10 04:44:07 +00007
Terry Jan Reedyc5a72e62014-06-24 22:21:41 -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öwis97cf99f2008-06-10 04:44:07 +000015 -------------------------------------------
16 Play around by clicking into the canvas
17 using all three mouse buttons.
18 -------------------------------------------
19 To exit press STOP button
20 -------------------------------------------
21"""
Martin v. Löwis60ebb8b2008-09-21 07:32:10 +000022from turtle import *
Martin v. Löwis97cf99f2008-06-10 04:44:07 +000023
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()