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