(root)/
Python-3.11.7/
Lib/
turtledemo/
paint.py
       1  #!/usr/bin/env python3
       2  """       turtle-example-suite:
       3  
       4              tdemo_paint.py
       5  
       6  A simple  event-driven paint program
       7  
       8  - left mouse button moves turtle
       9  - middle mouse button changes color
      10  - right mouse button toggles between pen up
      11  (no line drawn when the turtle moves) and
      12  pen down (line is drawn). If pen up follows
      13  at least two pen-down moves, the polygon that
      14  includes the starting point is filled.
      15   -------------------------------------------
      16   Play around by clicking into the canvas
      17   using all three mouse buttons.
      18   -------------------------------------------
      19            To exit press STOP button
      20   -------------------------------------------
      21  """
      22  from turtle import *
      23  
      24  def switchupdown(x=0, y=0):
      25      if pen()["pendown"]:
      26          end_fill()
      27          up()
      28      else:
      29          down()
      30          begin_fill()
      31  
      32  def changecolor(x=0, y=0):
      33      global colors
      34      colors = colors[1:]+colors[:1]
      35      color(colors[0])
      36  
      37  def 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  
      51  if __name__ == "__main__":
      52      msg = main()
      53      print(msg)
      54      mainloop()