turtle.down() or turtle.pendown() function in Python

The turtle.down() or turtle.pendown() function puts the pen down. When the pen is down, the turtle draws a line as it moves.

Syntax: turtle.pendown() or turtle.down()
Parameters: None.

Let us see an example to implement the turtle.pendown() function in Python:

Demo19.py

# turtle.pendown() function in Python
# Code by Studyopedia

import turtle

window = turtle.Screen()
t = turtle.Turtle()

t.penup()
t.forward(50)   # Moves without drawing
t.pendown()     # Put the pen down
t.forward(50)   # Draws a line

window.exitonclick()

The following is the output:

turtle.pendown() function in Python

In the above code, we followed the below steps:

  1. Import the module: import turtle loads Python’s turtle graphics library.
  2. Create the screen: window = turtle.Screen() opens the drawing window.
  3. Create the turtle: t = turtle.Turtle() creates the turtle (your pen).
  4. Lift the pen: t.penup() raises the pen so movements won’t draw.
  5. Move without drawing: t.forward(50) advances 50 units with no line.
  6. Lower the pen: t.pendown() puts the pen back down to resume drawing.
  7. Draw a line: t.forward(50) moves 50 units and draws a line.
  8. Close on click: window.exitonclick() keeps the window open until you click, then closes.

If you liked the tutorial, spread the word and share the link and our website, Studyopedia, with others.


For Videos, Join Our YouTube Channel: Join Now


Read More:

turtle.up() or turtle.penup() function in Python
turtle.isdown() function in Python
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment