In this Python tutorial, we will learn about how to use Turtle Pen in Python Turtle and we will also cover different examples related to Turtle Pen in Python. And, we will cover these topics.
- Python turtle pen
- Python turtle pen size
- Python turtle pen speed
- Python turtle penup
- Python turtle pen shape
- Python turtle pen color RGB
- Python turtle pen down
- Python turtle pen color
Python turtle pen
In this section, we will learn about the turtle pen in python turtle.
Before moving forward, we should have a piece of knowledge about a pen. A pen is a tool for writing or drawing some shapes on paper, a book, or a notebook. Here we use a turtle pen which is used to make shapes on a screen.
Code:
In the following code, we will import the turtle module from turtle import *, import turtle. The turtle() method is used to make objects.
print(tur.pen()) is used to print the default values of pen.
from turtle import *
import turtle as tur
print(tur.pen())
Output:
After running the above code, we get the following output in which we can see the default value of the pen is printed on the screen.
Also, check: Python Turtle Graphics
Python turtle pen size
In this section, we will learn about the size of the turtle pen in python turtle.
As we know the pen is used for drawing pictures, shapes. To look our shapes and pictures beautiful, we give a size to the pen. Which changes the size according to the shape they need from which out shape look attractive.
Code:
In the following code, we will import the turtle module from turtle import *, import turtle. The turtle() method is used to make shapes.
- tur.forward(100) is used to move the pen in the forward direction.
- tur.width(4) is used to give the size or width to the pen.
- tur.right(90) is used to move the turtle in the right direction.
from turtle import *
import turtle as tur
tur.forward(100)
tur.width(4)
tur.forward(100)
tur.right(90)
tur.forward(100)
tur.done()
Output:
After running the above code, we get the following output in which we can see the pen is moving in the forward direction with a thin line. After increasing the pen size, the shape of the line changed and the line look bold and thick.
Read: Python Turtle Screen Size
Python turtle pen speed
In this section, we will learn about the speed of a turtle pen in a python turtle.
Speed is used to increase the speed of the pen. Here we use the speed() function to change the speed of the pen by giving the value as an argument. The speed of the pen is lies between 0-10.
- Speedstrings are drawn by the speed value in the following way:
- Fastest: 0
- Slowest: 1
- Slow: 3
- Normal: 6
- Fast: 10
Code:
In the following code, we will import the turtle module from turtle import *, import turtle. The turtle() method is used to make objects.
Here we create a screen and this screen works as a drawing board where the user can draw shapes with the help of a pen at a slower speed.
- tur.speed(1) is used to give the slowest speed to the pen.
- tur.forward(200) is used to move the pen in the forward direction.
from turtle import *
import turtle as tur
tur.speed(1)
tur.forward(200)
tur.exitonclick()
Output:
After running the above code we get the following output in which we can see the pen move forward with the slowest speed.
Read: Python turtle onclick
Python turtle penup
In this section, we will learn about how to work with penup in python turtle.
As clear from the word pen up means to pick up the pen and turtle stop drawing it does not draw ant line as it moves. Here we can see where the penup() function starts the turtle stop drawing.
Code:
In the following code, we will import the turtle module from turtle import *, import turtle. The turtle() method is used to make objects.
- tur.color(“brown”) is used to give the color to the pen.
- tur.speed(1) is used to give the speed to the pen.
- tur.left(90) is used to move the turtle in the left direction.
- tur.width(5) is used to give the width to the pen.
- tur.penup() is used to stop the drawing.
from turtle import *
import turtle as tur
tur.color("brown")
tur.hideturtle()
tur.speed(1)
tur.left(90)
for i in range(4):
tur.width(5)
tur.forward(30)
tur.penup()
tur.forward(30)
tur.exitonclick()
Output:
After running the above code, we will get the following output in which we can see a single line is drawn on the screen because of the penup() method.
Read: Python Turtle Race
Python turtle pen shape
In this section, we will learn about how to draw shapes with the help of a pen in a python turtle.
We can draw a different shape with the help of a pen.shape() function. We can add shapes to the argument and change the shape of a pen.
Code:
In the following code, we will import the turtle module from turtle import *, import turtle as tur. The turtle() method is used to make objects.
- tur.forward(100) is used to move the turtle in the forward direction.
- tur.shape(“circle”) is used to give the circle shape to the pen.
- tur.right(60) is used to move the turtle in the right direction.
- tur.shape(“triangle”) is used to give a triangle shape to the pen.
- tur.shape(“square”) is used to give a square shape to the pen.
- tur.shape(“arrow”) is used to give the arrow shape to the pen.
- tur.shape(“turtle”) is used to give turtle shape to the pen.
from turtle import *
import turtle as tur
tur.forward(100)
tur.shape("circle")
tur.right(60)
tur.forward(100)
tur.shape("triangle")
tur.right(60)
tur.forward(100)
tur.shape("square")
tur.right(60)
tur.forward(100)
tur.shape("arrow")
tur.right(60)
tur.forward(100)
tur.shape("turtle")
tur.right(60)
tur.forward(100)
tur.done()
Output:
After running the above code, we get the following output in which we can see the pen changes its shapes as they move forward.
Read: Python Turtle Tracer
Python turtle pen color RGB
In this section, we will learn about the turtle pen color RGB in python turtle.
As we know the pen is used for drawing a picture on the drawing board. Here the screen is worked as a drawing board. We can draw any shape on a drawing board with help of a pen and also give the color with tur.pencolor() function which gives an attractive look to the picture. We create an RGB color to make a shape.
Code:
In the following code, we will import the turtle module from turtle import *, import turtle. The turtle() method is used to make shapes.
- tur.shape(“triangle”) is used to give the triangle shape to the pen.
- tur.forward(100) is used to move the turtle in the forward direction.
- tur.pencolor(“red”) is used to give the red color to the pen.
- tur.right(90) is used to move the pen in the right direction.
- tur.forward(100) is used to move the pen in the forward direction.
- tur.pencolor(“blue”) is used to give blue color to the pen.
- tur.pencolor(“green”) is used to give green color to the pen.
from turtle import *
import turtle as tur
tur.shape("triangle")
tur.colormode(255)
tur.forward(100)
tur.pencolor("red")
tur.right(90)
tur.forward(100)
tur.pencolor("blue")
tur.right(90)
tur.forward(100)
tur.pencolor("green")
tur.right(90)
tur.forward(100)
tur.done()
Output:
After running the above code we get the following output in which we can see a beautiful square shape with RGB color is drawn on the screen.
Read: Python Turtle Triangle
Python turtle pen down
In this section, we will learn about turtle pen down in python turtle.
As clear from the word pen down mean down the pen and start the drawing. pendown() method is used to go back to its previous drawing state and state to draw the picture, shape.
Code:
In the following code, we will import the turtle module from turtle import *, import turtle. The turtle() method is used to make objects.
- tur.color(“blue”) is used to give color to pen.
- tur.hideturtle() is used for hiding the turtle from the screen.
- tur.speed(1) is used to give the speed to the pen.
- tur.left(90) is used to move the turtle in the left direction.
- tur.forward(30) is used to move the turtle in the forward direction.
- tur.right(90) is used to move the turtle in the right direction.
- tur.pendown() is used to start the drawing.
from turtle import *
import turtle as tur
tur.color("blue")
tur.hideturtle()
tur.left(90)
for i in range(4):
tur.forward(30)
tur.right(90)
tur.forward(50)
tur.pendown()
tur.exitonclick()
Output:
After running the above code we will get the following output in which we can see after using the pendown() method it goes back to its previous drawing state and start drawing.
Read: Python Turtle Size
Python turtle pen color
In this section, we will learn about how to give the color to pen in python turtle.
As we know the pen is used for drawing pictures, shapes on the drawing board. Here the screen works as a drawing board and we can also give the color to pen for drawing beautiful and colorful shapes on the board which attracts the user when they see the picture.
Code:
In the following code, we will import the turtle module from turtle import *, import turtle. The turtle() method is used to make objects.
- tur.shape(“turtle”) is used to give the shape to the pen.
- tur.forward(100) is used for moving the pen in the forward direction.
- tur.right(90) is used to move the pen in the right direction.
- tur.pencolor(“cyan”) is used to give the color to the pen.
- tur.backward(120) is used to move the pen in the backward direction.
from turtle import *
import turtle as tur
tur.shape("turtle")
tur.colormode(255)
tur.forward(100)
tur.right(90)
tur.pencolor("cyan")
tur.forward(120)
tur.right(90)
tur.backward(120)
tur.right(90)
tur.done()
Output:
After running the above code we get the following output in which we can see that the default color of the pen is black we change the color of the pen with the help of pencolor() function.
You may also like to read the following articles on python Turtle.
- Python Turtle Square – Helpful Guide
- Python Turtle Window with examples
- Python Turtle Art – How to draw
- Python Turtle Write Function
- Python turtle input with examples
- Python turtle draw letters
So, in this tutorial, we discussed Python Turtle Pen and we have also covered different examples related to its implementation. Here is the list of examples that we have covered.
- Python turtle pen
- Python turtle pen size
- Python turtle pen speed
- Python turtle penup
- Python turtle pen shape
- Python turtle pen color RGB
- Python turtle pen down
- Python turtle pen color
I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.