After this lesson, you will be able to create basic graphics in Python using the Turtle Library.
Input:
import turtle
window = turtle.Screen()
window.bgcolor('black')
Bob = turtle.Turtle()
Bob.begin_fill()
Bob.color('white')
Bob.forward(100)
Bob.left(90)
Bob.forward(100)
Bob.left(90)
Bob.forward(100)
Bob.left(90)
Bob.forward(100)
Bob.up()
Bob.forward(100)
Bob.end_fill()
Bob.color('black')
Output:

import turtle
window = turtle.Screen()
window.bgcolor('black')
Whenever you want to use the Turtle Library, use import turtle.
In order for the window (where the turtle is being executed) to show up, you just write the window variable name = turtle.Screen().
Since I wanted to change the color of my window, I used window.bgcolor(‘color’) to change my background color. I used window.bgcolor(‘black’) to change my background color black. If you want to use different string colors, this link has a variety of different colors that can be used. Using the link, just click on the color you like and put it in the string.
Bob = turtle.Turtle()
Bob.begin_fill()
Bob.color('white')
For this part of the code, I named my turtle ‘Bob’ in Bob = turtle.Turtle().
I wanted my turtle to be filled in so I used Bob.begin_fill() to begin filling Bob.
I then selected white to be the color that I wanted Bob to be filled in with using Bob.color(‘white’).
Bob.forward(100)
Bob.left(90)
Bob.forward(100)
Bob.left(90)
Bob.forward(100)
Bob.left(90)
Bob.forward(100)
Bob.up()
Bob.forward(100)
Bob.color('black')
Bob.end_fill()
Bob.color('black')
This is the part where I started to tell bob where to go and what to do. I used Bob.forward(100) to make him go in the forward direction for 100 units. Here’s how the output of the first line of this part of the code looked like:

I then used Bob.left(90) to make Bob turn left 90 degrees and made him go forward again by 100 units. Here’s how this looked like: Since I chose to fill the object in, it looks like a triangle, which is half of a square. It looks like this because we are halfway done.

I kept repeating the process till I got a square:

The arrow at the bottom of the square was slightly annoying to me, so to move the arrow away from the square, I used Bob.up() to basically lift Bob’s tail up and moved it forward a hundred units. I then ended the fill color using Bob.end_fill().I then changed the background color to black to make the white arrow black and blend it in with the background.




