In this Python tutorial, we will discuss python turtle commands and, we will see the syntax used for python turtle. Also, we will see the below topics as:
- Python turtle shape() commands
- Python turtle up() commands
- Python turtle down() commands
- Python turtle backward() commands
- Python turtle forward() commands
- Python turtle color() commands
- Python turtle position() commands
- Python turtle goto() commands
- Python turtle left() commands
- Python turtle right() commands
- Python turtle begin_fill() commands
- Python turtle end_fill() commands
- Python turtle fillcolor() commands
- Python turtle window_width() commands
- Python turtle dot() commands
Python turtle shape() commands
The turtle shape() command is used to set the turtle shape with a given name, if the shape is not given then it returns the default shape. Here, the name will be the string parameters like triangle, square, circle, arrow, and classic.
Syntax:
turtle.shape(name)
Python turtle up() commands
The turtle up() command stops all drawing. It pull the pen up and nothing will be drawn to the screen, until down is called.
Syntax:
turtle.up()
Read Python Turtle Write Function
Python turtle down() commands
The turtle down() command is used to pull back the pen down on the screen and it starts drawing when moving.
Syntax:
turtle.down()
Example:
import turtle
turtle.forward(40)
turtle.up()
turtle.forward(40)
turtle.down()
turtle.forward(30)
turtle.done()
You may like Python Pandas CSV Tutorial.
Python turtle backward() commands
The turtle backward() command is used to move the turtle backward by a specified distance, which is opposite to the direction of the turtle head.
Syntax:
turtle.backward(distance)
Python turtle forward() commands
The turtle forward() command is used to move the turtle forward by the specified distance, in the direction the turtle headed.
Syntax:
turtle.forward(distance)
Python turtle color() commands
The turtle color() command is used to change the color of the turtle, and the default color of the turtle is “black”.
Syntax:
turtle.color(*args)
Example:
import turtle
turtle.forward(40)
turtle.color("orange")
turtle.forward(60)
turtle.done()
Python turtle position() commands
The turtle position() command is used to return the turtle current position (x,y).
Syntax:
turtle.position()
Python turtle goto() commands
The python turtle goto() command is used to move the turtle from the current position to the x,y location along the shortest linear path between the two locations.
Syntax:
turtle.goto(x,y)
Python turtle left() commands
The turtle left() command is used to change the direction of the turtle by the given value of the argument. So, it turns the turtle counter clockwise
Syntax:
turtle.left(angle)
Example:
import turtle
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.done()
Python turtle right() commands
The python turtle right() command is used to change the direction of the turtle by the given value of the argument. So, it turns the turtle clockwise.
Syntax:
turtle.right(angle)
Example:
import turtle
turtle.forward(100)
turtle.right(90)
turtle.forward(100)
turtle.done()
Python turtle begin_fill() commands
In python, the turtle begin_fill() command is used to call just before drawing a shape to be filled. It does not take any argument.
Syntax:
turtle.begin_fill()
Python turtle end_fill() commands
The turtle end_fill() command is used to fill the shape drawn after the last call to begin_fill(). It does not take any argument.
Syntax:
turtle.end_fill()
Python turtle fillcolor() commands
The turtle fillcolor() command is used to return or set the fillcolor. If the turtle shape is polygon then we can set the interior color with the newly set fillcolor.
Syntax:
turtle.fillcolor(*args)
Python turtle window_width() commands
The turtle window_width() command is used to return the width of the current window in pixels. It does not require any argument.
Syntax:
turtle.window_width()
Python turtle dot() commands
The turtle dot() command is used to draw a circular dot with a particular size in the current position, with some color. We can set the size and color.
Syntax:
turtle.dot(size, *color)
Example:
import turtle
turtle.forward(120)
turtle.dot(30, "red")
turtle.done()
You may like the following Python tutorials:
- How to write Python array to CSV
- Python shape of an array
- Python Turtle Speed With Examples
- How to make a smiling face in python turtle
- How to Create a Snake game in Python using Turtle
- Draw colored filled shapes using Python Turtle
- Python list comprehension using if-else
- Python read a binary file
- Check if a list exists in another list Python
In this tutorial, we have learned about python turtle commands with the syntax, also we have covered these topics:
- Python turtle shape() commands
- Python turtle up() commands
- Python turtle down() commands
- Python turtle backward() commands
- Python turtle forward() commands
- Python turtle color() commands
- Python turtle position() commands
- Python turtle goto() commands
- Python turtle left() commands
- Python turtle right() commands
- Python turtle begin_fill() commands
- Python turtle end_fill() commands
- Python turtle fillcolor() commands
- Python turtle window_width() commands
- Python turtle dot() commands
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.