Draw Square and Rectangle in Turtle – Python
Last Updated :
11 Apr, 2025
The task of drawing basic geometric shapes, such as squares and rectangles, can be accomplished using Python’s Turtle graphics library. Turtle graphics enables us to create shapes and patterns by controlling a “turtle” on the screen. Using simple commands like forward(), backward(), and others, we can easily draw squares and rectangles.
To get started with the Turtle module, you need to import it into your Python script:
import turtle
Drawing Square
Using Manual Turning (Non-loop Method)
In this approach, we will manually draw each side of the square and turn the turtle 90 degrees after each side. The process is repeated four times to complete the square.
[GFGTABS]
Python
import turtle
t = turtle.Turtle()
s = int(input("Enter the length of the side of the Square:"))
# drawing first side
t.forward(s)
t.left(90)
# drawing second side
t.forward(s)
t.left(90)
# drawing third side
t.forward(s)
t.left(90)
# drawing fourth side
t.forward(s)
t.left(90)
[/GFGTABS]
Input
100
Output

Explanation: In this code, we start by asking the user for the length of the side of the square. Then, we manually draw each side of the square by using t.forward(s) to move the turtle forward by s units and t.left(90) to turn the turtle by 90 degrees after each side. This process is repeated four times, each time drawing one side of the square. The left(90) ensures the turtle turns by 90 degrees to form right angles.
Using Loop
This method uses a loop to repeat the process of drawing each side of the square, reducing redundancy and making the code more efficient.
[GFGTABS]
Python
import turtle
t = turtle.Turtle()
s = int(input("Enter the length of the side of square:"))
for _ in range(4):
t.forward(s)
t.left(90)
[/GFGTABS]
Input
100
Output

Explanation: In this approach, the user is again prompted to enter the side length of the square. A loop runs four times (for _ in range(4)), and during each iteration, the turtle moves forward by the specified side length (t.forward(s)) and turns 90 degrees (t.left(90)). This method achieves the same result as the first, but in a more concise and reusable manner by utilizing a loop instead of manually repeating the commands.
Drawing Rectangle
Using Manual Turning (Non-loop Method)
In this approach, we will manually draw each side of a rectangle and turn the turtle by 90 degrees after each side. The process is repeated for all four sides of the rectangle.
[GFGTABS]
Python
import turtle
t = turtle.Turtle()
l = int(input("Enter the length:"))
w = int(input("Enter the width:"))
# drawing first side
t.forward(l)
t.left(90)
# drawing second side
t.forward(w)
t.left(90)
# drawing third side
t.forward(l)
t.left(90)
# drawing fourth side
t.forward(w)
t.left(90)
[/GFGTABS]
Input
100
120
Output

Explanation: In this code, the user is asked to input the length (l) and width (w) of the rectangle. The turtle then begins drawing by moving forward by the length of the rectangle (t.forward(l)) and turns 90 degrees using t.left(90). The process is repeated for the second side (width), and this continues for the remaining two sides of the rectangle.
Using Loop
This method uses a loop to draw the rectangle, making the code more compact and reusable while alternating between length and width.
[GFGTABS]
Python
import turtle
t = turtle.Turtle()
l = int(input("Enter the length:"))
w = int(input("Enter the width:"))
for _ in range(4):
# drawing length
if _% 2 == 0:
t.forward(l)
t.left(90)
# drawing width
else:
t.forward(w)
t.left(90)
[/GFGTABS]
Input
100
120
Output

Explanation: This approach uses a loop (for _ in range(4)) to repeat the drawing steps. The loop alternates between drawing the length and the width of the rectangle using an if condition (if _% 2 == 0). For even iterations (_ % 2 == 0), the turtle moves forward by the length of the rectangle, and for odd iterations, it moves forward by the width. After each side, the turtle turns by 90 degrees (t.left(90)).
Drawing a Character Using Turtle Graphics
Since as of now, you must have learned how to draw various basic geometrical illustrations like circle, square, rectangle. So, let’s implement this knowledge to build something which you can really use in building games like let’s draw a human being using the basic knowledge of geometrical knowledge.
[GFGTABS]
Python
import turtle
def draw_dream():
window = turtle.Screen()
window.bgcolor("white")
draw_Scarlett()
window.exitonclick()
def draw_Scarlett():
brad = turtle.Turtle()
brad.shape("turtle")
brad.color("red")
draw_head(brad)
draw_body(brad)
draw_arm(brad)
draw_leg1(brad)
draw_leg2(brad)
def draw_head(brad):
brad.circle(60)
brad.speed(3)
brad.right(60)
def draw_body(brad):
num = 0
while num < 3:
brad.forward(150)
brad.right(120)
brad.speed(1)
num += 1
def draw_arm(brad):
brad.forward(60)
brad.left(60)
brad.forward(60)
brad.backward(60)
brad.right(60)
brad.backward(60)
brad.right(60)
brad.forward(60)
brad.right(60)
brad.forward(60)
brad.backward(60)
brad.left(60)
brad.forward(90)
def draw_leg1(brad):
brad.left(120)
brad.forward(40)
brad.right(120)
brad.forward(120)
draw_foot1(brad)
def draw_leg2(brad):
brad.color("red")
brad.right(180)
brad.forward(120)
brad.right(60)
brad.forward(70)
brad.right(60)
brad.forward(120)
draw_foot2(brad)
def draw_foot1(brad):
brad.color("blue")
num = 0
while num < 4:
brad.forward(20)
brad.right(90)
num += 1
def draw_foot2(brad):
brad.color("blue")
num = 0
while num < 4:
brad.forward(20)
brad.left(90)
num += 1
draw_dream()
[/GFGTABS]
Output

Explanation:
- draw_dream(): Initializes the Turtle window and starts the drawing of the character.
- draw_Scarlett(): Creates the turtle and calls functions to draw different body parts.
- draw_head(brad): Draws the head as a circle.
- draw_body(brad): Draws the body using a triangle.
- draw_arm(brad) and draw_leg1(brad), draw_leg2(brad): Draw the arms and legs with specific angles and movements.
- draw_foot1(brad) and draw_foot2(brad): Draws square-shaped feet with blue color.
Related Articles:
Similar Reads
Draw Spiraling Square using Turtle in Python
Prerequisite: Python Turtle Basic Turtle is an inbuilt module of python. It enables us to draw any drawing by a turtle, methods defined in the turtle module and by using some logical loops. To draw something on the screen(cardboard) just move the turtle(pen). To move turtle(pen) there are some funct
1 min read
Draw Spiraling Star using Turtle in Python
Prerequisite: Python Turtle Basics Turtle is an inbuilt module of python. It enables us to draw any drawing by a turtle and methods defined in the turtle module and by using some logical loops. To draw something on the screen(cardboard) just move the turtle(pen).To move turtle(pen) there are some fu
1 min read
Draw any polygon in Turtle - Python
Prerequisite: Python Turtle Basics Turtle is an inbuilt module of python. It enables us to draw any drawing by a turtle and methods defined in the turtle module and by using some logical loops. turtle drawings are basically drawn using four methods defined in the turtle module. forward(x): moves the
2 min read
turtle.register_shape() function in Python
The turtle module provides turtle graphics primitives, in both object-oriented and procedure-oriented ways. Because it uses tkinter for the underlying graphics, it needs a version of Python installed with Tk support. turtle.register_shape() This function is used to add a turtle shape to TurtleScreen
1 min read
Draw Spiraling Triangle using Turtle in Python
Prerequisite: Python Turtle Basic Turtle is an inbuilt module of python. It enables us to draw any drawing by a turtle, methods defined in the turtle module, and by using some logical loops. To draw something on the screen(cardboard) just move the turtle(pen). To move turtle(pen) there are some func
1 min read
turtle.settiltangle() function in Python
The turtle module provides turtle graphics primitives, in both object-oriented and procedure-oriented ways. Because it uses Tkinter for the underlying graphics, it needs a version of Python installed with Tk support. turtle.settiltangle() This function is used to rotate the turtleshape to point in t
2 min read
Python PIL | ImageDraw.Draw.rectangle()
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The ImageDraw module provide simple 2D graphics for Image objects. You can use this module to create new images, annotate or retouch existing images, and to generate graphics on the fly for web u
2 min read
Draw a triangle using Arcade in Python
Arcade is a Python library that is used for developing 2Dimensional Games. Arcade needs support for OpenGL 3.3+. In the arcade, basic drawing does not require knowledge on how to define functions or classes or how to do loops, simply we have inbuilt functions for drawing primitives. Arcade inbuilt f
2 min read
Draw a Sine wave using Turtle in Python
In this article, we will draw a sinewave using a turtle in Python. Turtle is one of the modules in python, it is a graphic that refers to controlling a graphical entity in a graphics window with x, and y coordinates. It is a toolkit that provides a simple and enjoyable way to draw pictures and shape
3 min read
Draw Color Filled Shapes in Turtle - Python
In Python's Turtle module, we can create visually appealing graphics by drawing shapes and filling them with colors. This allows us to design colorful patterns, logos, and illustrations. Let's explore how to draw and fill different shapes using Turtle in Python. Steps to draw color-filled shapes in
4 min read