In this tutorial, we will learn How to Write some Functions in Python Turtle and we will also cover different examples related to Turtle Write. And, we will cover these topics.
- Python Turtle Write Function
- PythonTurtle Write Name
- Python Turtle Write Position
- Python Turtle Write Text
- Python Turtle Write Text Color
- Python Turtle Write Text Size
- Python Turtle Write Font Size
- Python Turtle Write Letters
- Python Turtle Write Fonts
- Python Turtle Write Align
Python Turtle Write Function
In Python turtle is used for writing the text on the screen and it is also used to draw different shapes. The turtle is worked as a pen. We can write different texts, words, and paragraphs with the help of the tutle.write() function.
Code:
In the following code, we will import the turtle module from which we can write text on the screen with the help of the turtle.
- turtle.title(“Pythontpoint”) is used to give the title to the screen.
- turtle.write(“PythonTPoint” , move=True,align=’center’,font=(‘Times New Roman’,18,’bold’)) is used to write the text on the screen.
from turtle import *
import turtle
turtle.title("Pythontpoint")
wd=turtle.write("PythonTPoint" , move=True,align='center',font=('Times New Roman',18,'bold'))
turtle.done()
Output:
After running the above code we get the following output in which we can see that the text is written on the screen with the help of turtle.write() function.
PythonTurtle Write Name
As we know we can use turtle for different purposes we can write, draw different shapes with the help of the turtle. Here turtle is working as a pen. And we write the name and draw a different shape on the screen and here the screen works as a drawing board.
Code:
In the following code, we will import the turtle library from which we can write the name and also give a beautiful color to the name.
- turt.title(“Pythontpoint”) is used to give the title to the screen.
- turt.color(‘blue’) is used to give color to the turtle.
- turt.write(‘PythonTpoint’, font=style, align=’center’) is used to writing the name on the screen.
- turt.hideturtle() is used for hiding the turtle from the screen.
from turtle import *
import turtle as turt
turt.title("Pythontpoint")
turt.color('blue')
style = ('Courier', 30, 'bold')
turt.write('PythonTpoint', font=style, align='center')
turt.hideturtle()
turt.done()
Output:
After running the above code we get the following output in which we can see that the Name of our website is written on the screen.
Python Turtle Write Position
In Python turtle we can write text on the screen with the help of tur.write() function. We can also set the position of the turtle on which position we want to write the text on the screen.
Code:
In the following code, we will import turtle modules from which we can write the text with their given position on the screen.
- turtle.title(“Pythontpoint”) is used to give the title on the screen.
- oday1 = datetime.datetime.now() it is used to show the current time on the screen.
- tur.write(message,move=False, font=(‘Times New Roman’,12,’bold’),align=’left’) is used to write the text on the screen.
from turtle import *
import turtle
import datetime
turtle.title("Pythontpoint")
tur = turtle.Turtle()
today1 = datetime.datetime.now()
tur.hideturtle()
tur.penup()
tur.backward((tur.getscreen().window_width() / 2) - 10)
message = "Hello Welcome to PythonTpoint! \nToday is " + today1.strftime("%A") + ', ' + today1.strftime("%d") \
+ ', ' + today1.strftime("%B") + ', ' + today1.strftime("%Y")
tur.write(message,move=False, font=('Times New Roman',12,'bold'),align='left')
turtle.exitonclick()
Output:
After running the above code we get the following output in which we can see that the left position is given to the tecxt.
Python Turtle Write Text
In Python turtle, we can write any type of text with the help of turt.write() function.We can also rewrite the text just simply removing the previous text from the argument and putting the new text in it.
Code:
In the following code, we will import the turtle module from which we can write the text on the screen with the help of turt.write() function.
- turt.title(“Pythontpoint”) is used to give the title to the screen.
- turt.write(“Hello Pythonpoint Users”, font=(“Verdana”, 15, “normal”)) is used to give the text on the screen.
from turtle import *
import turtle as turt
turt.title("Pythontpoint")
turt.write("Hello Pythonpoint Users", font=("Verdana",
15, "normal"))
turt.exitonclick()
Output:
After running the above code we get the following output in which we can see that the text is written with the help of turt.write() function.
Python Turtle Write Text Color
Write color is used to give the color to the text. After giving color to the text our text looks attractive and it attracts the user’s eye . If we don’t give any color to the text the default color is automatically given to the text. The default color of the turtle is black.
Code:
In the following code, we will import the turtle module from which we write the text and give the color to the text.
- The turtle() method is used to make objects.
- turtle.title(“Pythontpoint”) is used to give the title to the screen.
- tur.fillcolor(‘blue’) is used to fill the color inside the shape.
- tur.color(‘red’) is used to give the color to the turtle.
- tur.forward(50) is used to move the turtle in the forward direction.
- tur.left(90) is used to move the turtle in the left direction.
- tur.write(‘PythonTpoint’) is used to write the text on the screen.
from turtle import *
import turtle
turtle.title("Pythontpoint")
def tur():
tur = turtle.Turtle()
tur.fillcolor('blue')
tur.begin_fill()
tur.color('red')
for i in range(4):
tur.forward(50)
tur.left(90)
tur.end_fill()
def win():
tur = turtle.Turtle()
tur.color('blue')
tur.fillcolor('red')
tur.begin_fill()
tur.penup()
tur.goto(0, -20)
tur.pendown()
tur.write('PythonTpoint')
tur.end_fill()
tur()
win()
turtle.done()
Output:
After running the above code we get the following output in which we can see that the shape is drawn with the help of turtle and below the shape text is written with a beautiful color.
Read: Python Turtle Speed
Python Turtle Text Size
The Text size defines how large our text is displayed on the screen. We can also change the size of the text simply by changing the font size. If we want our text to look large then we can give the large number to them for size.
Code:
In the following code, we will import the turtle module from which we can write the text and also give a size to the text.
- The turtle() method is used to make shapes.
- text_size.write(“PythonTpoint”, font=(“Times New Roman”, 25, “bold”)) is used to write the text and give the size to the text.
from turtle import *
import turtle
turtle.title("Pythontpoint")
text_size = turtle.Turtle()
text_size.write("PythonTpoint", font=("Times New Roman", 25, "bold"))
turtle.done()
After running the above code we get the following output in which we can see that the text is written on the screen with a suitable size.
Read: Python Turtle Circle
Python Turtle Write Font Size
Font size is that which we give to our text to increase or decrease the size of our text. If the size of the text looks very large then we want to chant the font size and our text size also changes. We can change the size of the text if we want just simply change the font size.
Code:
In the following code, we will import the turtle module from which we can change the size of the font from which our text size also changes.
- turtle.title(“Pythontpoint”) is used to give the title to the window.
- fontsize.write(“Welcome To PythonTpoint”, font=(“Times New Roman”, 18, “bold”)) is used to write the text on the screen and also change this text size with change in the font size.
from turtle import *
import turtle
turtle.title("Pythontpoint")
fontsize = turtle.Turtle()
fontsize.write("Welcome To PythonTpoint", font=("Times New Roman", 18, "bold"))
turtle.done()
Output:
After running the above code in which we can see that the text is written on the screen with a given font size which looks attractive.
Python Turtle Write Letters
In python, the turtle is used to draw and write the text on the screen. We can also write letters using turtle.write() function with the help of a turtle.
Code:
In the following code, we will import the turtle module from which we can write letters with the help of the turtle.write() function.
wd=turtle.write(“PTP” , move=True,align=’center’,font=(‘Times New Roman’,25,’bold’)) is used to write the letters on the screen.
from turtle import *
import turtle
turtle.title("Pythontpoint")
wd=turtle.write("PTP" , move=True,align='center',font=('Times New Roman',25,'bold'))
turtle.done()
Output:
After running the above code we get the following output in which we can see that the letters “PTP” are written on the screen.
Python Turtle Write Fonts
As we know the turt.write() function is used to write the text we can also give font to the text. We can give any font style to the text like arial, Times New Roman, Verdana, etc. These fonts give a different style to text and from this, our text looks attractive.
from turtle import *
import turtle as turt
turt.title("Pythontpoint")
turt.write("Hello Pythonpoint Users", font=("Verdana",15, "normal"))
turt.exitonclick()
Output:
After running the above code we get the following output in which we can see that a text is written on the screen with a beautiful font style.
Python Turtle Write Align
Before moving forward we should have some piece of knowledge about align. Alignment is used to give align to the text as per the requirement of the page. If we want to change the position of the text then we can change the alignment we can give text-align center, align-left, and align right.
Code:
In the following code, we will import the turtle module from which we can write the text and give the alignment to the text.
- The turtle() method is used to make objects.
- turtle.write(“Heya Pythontpoint User”, align=”center”, font=FONT) is used to write the text on the screen and also give alignment to the text.
from turtle import Turtle, Screen
import turtle
FONTSIZE = 30
FONT = ("Times New Roman", FONTSIZE, "bold")
turtle.title("Pythontpoint")
turtle = Turtle()
turtle.penup()
turtle.home()
turtle.sety(-FONTSIZE/2)
turtle.write("Heya Pythontpoint User", align="center", font=FONT)
turtle.hideturtle()
screen = Screen()
screen.exitonclick()
Output:
After running the above code we get the following output in which we can see that the text is written on the screen with the center alignment.
So, in this tutorial, we discussed Python Turtle Write and we have also covered different examples related to its implementation. Here is the list of examples that we have covered.
- Python Turtle Write Function
- PythonTurtle Write Name
- Python Turtle Write Position
- Python Turtle Write Text
- Python Turtle Write Text Color
- Python Turtle Text Size
- Python Turtle Write Font Size
- Python Turtle Write Letters
- Python Turtle Write Fonts
- Python Turtle Write Align
Do follow the following tutorials also:
Comments are closed.