jpayne@68: #!/usr/bin/env python3 jpayne@68: """ turtle-example-suite: jpayne@68: jpayne@68: tdemo_paint.py jpayne@68: jpayne@68: A simple event-driven paint program jpayne@68: jpayne@68: - left mouse button moves turtle jpayne@68: - middle mouse button changes color jpayne@68: - right mouse button toggles between pen up jpayne@68: (no line drawn when the turtle moves) and jpayne@68: pen down (line is drawn). If pen up follows jpayne@68: at least two pen-down moves, the polygon that jpayne@68: includes the starting point is filled. jpayne@68: ------------------------------------------- jpayne@68: Play around by clicking into the canvas jpayne@68: using all three mouse buttons. jpayne@68: ------------------------------------------- jpayne@68: To exit press STOP button jpayne@68: ------------------------------------------- jpayne@68: """ jpayne@68: from turtle import * jpayne@68: jpayne@68: def switchupdown(x=0, y=0): jpayne@68: if pen()["pendown"]: jpayne@68: end_fill() jpayne@68: up() jpayne@68: else: jpayne@68: down() jpayne@68: begin_fill() jpayne@68: jpayne@68: def changecolor(x=0, y=0): jpayne@68: global colors jpayne@68: colors = colors[1:]+colors[:1] jpayne@68: color(colors[0]) jpayne@68: jpayne@68: def main(): jpayne@68: global colors jpayne@68: shape("circle") jpayne@68: resizemode("user") jpayne@68: shapesize(.5) jpayne@68: width(3) jpayne@68: colors=["red", "green", "blue", "yellow"] jpayne@68: color(colors[0]) jpayne@68: switchupdown() jpayne@68: onscreenclick(goto,1) jpayne@68: onscreenclick(changecolor,2) jpayne@68: onscreenclick(switchupdown,3) jpayne@68: return "EVENTLOOP" jpayne@68: jpayne@68: if __name__ == "__main__": jpayne@68: msg = main() jpayne@68: print(msg) jpayne@68: mainloop()