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