Pythondex
Turtle Python Programs

Draw Car In Python Turtle

Last updated July 3, 2023 by Jarvis Silva

Today in this tutorial we will see how to draw a car using python programming to create this program we will use the turtle module in python, It is a GUI python library which can be used to draw anything from characters, cartoons, shapes and other objects.

Python Code To Draw A Car


import turtle
   
    
myCar = turtle.Turtle()
  
  
# code for drawing rectangular upper body
myCar.color('black')
myCar.fillcolor('yellow')
myCar.penup()
myCar.goto(0,0)
myCar.pendown()
myCar.begin_fill()
myCar.forward(370)
myCar.left(90)
myCar.forward(50)
myCar.left(90)
myCar.forward(370)
myCar.left(90)
myCar.forward(50)
myCar.end_fill()
   
    
# code for drawing window and roof
myCar.penup()
myCar.goto(100, 50)
myCar.pendown()
myCar.setheading(45)
myCar.forward(70)
myCar.setheading(0)
myCar.forward(100)
myCar.setheading(-45)
myCar.forward(70)
myCar.setheading(90)
myCar.penup()
myCar.goto(200, 50)
myCar.pendown()
myCar.forward(49.50)
   
    
# code for drawing two tyres
myCar.penup()
myCar.goto(100, -10)
myCar.pendown()
myCar.color('black')
myCar.fillcolor('black')
myCar.begin_fill()
myCar.circle(20)
myCar.end_fill()
myCar.penup()
myCar.goto(300, -10)
myCar.pendown()
myCar.color('black')
myCar.fillcolor('black')
myCar.begin_fill()
myCar.circle(20)
myCar.end_fill()
   
    
myCar.hideturtle()

turtle.done()

Above is the python program to draw a car, as you can see from the code it is all done with the turtle module so let’s understand how the code works:

  • Importing the turtle module to use its functions and classes.
  • Creating a turtle object named myCar.
  • Drawing the rectangular upper body of the car:
    • Setting the color to black and fill color to yellow.
    • Moving the turtle to the starting position (0, 0).
    • Beginning the fill.
    • Moving the turtle forward by 370 units (length of the body).
    • Turning left by 90 degrees.
    • Moving the turtle forward by 50 units (height of the body).
    • Turning left by 90 degrees.
    • Moving the turtle forward by 370 units.
    • Turning left by 90 degrees.
    • Moving the turtle forward by 50 units.
    • Ending the fill.
  • Drawing the window and roof of the car:
    • Moving the turtle to the position (100, 50).
    • Setting the heading to 45 degrees.
    • Moving the turtle forward by 70 units.
    • Setting the heading to 0 degrees.
    • Moving the turtle forward by 100 units.
    • Setting the heading to -45 degrees.
    • Moving the turtle forward by 70 units.
    • Setting the heading to 90 degrees.
    • Moving the turtle to the position (200, 50).
    • Moving the turtle forward by 49.50 units (width of the roof).
  • Drawing the two tires:
    • Moving the turtle to the position (100, -10).
    • Setting the color and fill color to black.
    • Beginning the fill.
    • Drawing a circle with a radius of 20 units.
    • Ending the fill.
    • Moving the turtle to the position (300, -10).
    • Setting the color and fill color to black.
    • Beginning the fill.
    • Drawing a circle with a radius of 20 units.
    • Ending the fill.
  • Hiding the turtle to only display the car.
  • Ending the program with turtle.done(), which keeps the turtle graphics window open.

Now you know how the code works let’s run it to run this program you need to have python installed on your computer, If you don’t have then follow this guide: Install and setup python on your computer or else you can use this online python compiler

Now you have the code, but there is one last thing you might need to do as we have used the turtle library for this program so you might need to install it if you get any errors like turtle module not found use below command to install.


pip install turtle

After running this program it will open a new window and it will start drawing the car and below is the finished drawing of the car.

Car Drawing In Python Turtle

As you can see, we successfully drew the car using python turtle. I hope you were able to run this program successfully, do share this tutorial with your friends who might be interested in this program.

Here are some more python drawing tutorials for you:

I hope you found what you were looking for from this tutorial, and if you want more python guides and tutorials like this, do join our Telegram channel for future updates.

Thanks for reading, have a nice day 🙂