turtle.pen()

turtle.pen(pen=None, **pendict)

Parameters:
  • pen – a dictionary with some or all of the below listed keys
  • pendict – one or more keyword-arguments with the below listed keys as keywords

Return or set the pen’s attributes in a “pen-dictionary” with the following key/value pairs:

  • “shown”: True/False
  • “pendown”: True/False
  • “pencolor”: color-string or color-tuple
  • “fillcolor”: color-string or color-tuple
  • “pensize”: positive number
  • “speed”: number in range 0..10
  • “resizemode”: “auto” or “user” or “noresize”
  • “stretchfactor”: (positive number, positive number)
  • “outline”: positive number
  • “tilt”: number

This dictionary can be used as argument for a subsequent call to pen() to restore the former pen-state. Moreover one or more of these attributes can be provided as keyword-arguments. This can be used to set several pen attributes in one statement.

>>> turtle.pen(fillcolor="black", pencolor="red", pensize=10)
>>> sorted(turtle.pen().items())
[('fillcolor', 'black'), ('outline', 1), ('pencolor', 'red'),
 ('pendown', True), ('pensize', 10), ('resizemode', 'noresize'),
 ('shearfactor', 0.0), ('shown', True), ('speed', 9),
 ('stretchfactor', (1.0, 1.0)), ('tilt', 0.0)]
>>> penstate=turtle.pen()
>>> turtle.color("yellow", "")
>>> turtle.penup()
>>> sorted(turtle.pen().items())[:3]
[('fillcolor', ''), ('outline', 1), ('pencolor', 'yellow')]
>>> turtle.pen(penstate, fillcolor="green")
>>> sorted(turtle.pen().items())[:3]
[('fillcolor', 'green'), ('outline', 1), ('pencolor', 'red')]
doc_python
2016-10-07 17:45:35
Comments
Leave a Comment

Please login to continue.