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