Draw Square in Turtle Python

Draw Square in Turtle Python

Draw Square in Turtle Python

Hello coders! Today we will learn to draw a square from Turtle model in Python step by step, so let’s start our project Draw Square in Turtle Python, You can improve your skills by making this python project

Python Turtle has basic models to learn Python language.

The turtle allows you to direct different directions. Examples (square, cone, rectangle, circle, etc.)

First of all, we will need some libraries for this Python project which will help us in drawing Square in Turtle Python. import turtle

You can download the whole Draw Square in Turtle Python  code below.

Draw Square in Turtle Python

  • Install Python In your PC
  • Make sure you are install a Module 
  • Make sure you are install Interpreter in your PC

Lets start the code:

1. Installing the model and creating the window with name :-

import turtle

# Set up the turtle screen
screen = turtle.Screen()
screen.title("Python Square Drawing By CodeWithRandom")

2. Direction the Turtle:-

# Create a turtle named 'artist'
artist = turtle.Turtle()

Draw Square in Turtle Python

Giving directions to the turtle

3.  Repeat the turtle to make perfect square :-

# Draw a square
for _ in range(4):
    artist.forward(100)  # Adjust the length of the sides as desired
    artist.right(90)

Draw Square in Turtle Python

We will move forward, turn and repeat these steps.

4. Adding colour to Customizing our Square:-

# Add some flair
artist.color("blue")  # Set the color of the lines
artist.pensize(3)     # Set the thickness of the lines
artist.begin_fill()   # Begin filling the square
for _ in range(4):
    artist.forward(100)
    artist.right(90)
artist.end_fill()     # End the filling

Draw Square in Turtle Python

Add colors to Python Turtle to make it interesting our square.

5. final touch the square:-

# Draw multiple squares
for _ in range(6):
    artist.forward(100)
    artist.right(90)

Draw Square in Turtle Python

Final OutPut Preview:-

Here is full code of Draw Square in Turtle Python:-

import turtle

# Set up the turtle screen
screen = turtle.Screen()
screen.title("Python Square Drawing By CodeWithRandom")

# Create a turtle named 'artist'
artist = turtle.Turtle()

# Increase the size of the square
side_length = 150

# Draw a square
for _ in range(4):
    artist.forward(side_length)
    artist.right(90)

# Keep the window open until closed by the user
turtle.done()

Final Output Preview:-

Draw Square in Turtle Python

ADVERTISEMENT

 

We have drawn a square with Python Turtle and added colors to it to make it interesting. These are basic Python projects which you can also make easily.

ADVERTISEMENT

Happy coding, If there is anything missing please let us know, we will update it soon.

ADVERTISEMENT

Thanks for reading my article

Author:- Ashutosh Mishra

ADVERTISEMENT

Which function will be used to import turtle?

To import a Turtle model, you will have to write this code in your interpreter (import turtle)

ADVERTISEMENT

What code will i use to keep the window open while running Turtle Code?

To keep the window open while running the turtle code, we will need a turtle.mainloop() function



Leave a Reply