Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Turtle, draw text with on screen with larger font

I'm using python turtle's write method to write text on the screen like this:

turtle.write("messi fan")

The size of the font is too small. How can I increase the size of font?

like image 884
open source guy Avatar asked Feb 28 '13 16:02

open source guy


People also ask

How do you change font size in Python turtle?

In the following code, we import the turtle library import turtle and also write a text with help of the write() function inside the write() function we use font=('arial', 50, 'bold') to give a size to the text.

How do you write on a screen turtle?

If the user wants to write something on screen then they simply use the write() function. Code: In the following code, we use the write function to write text on the screen. turtle.

What does Penup () do in turtle?

penup or pu means pick pen up, so you can move turtle without leaving tracks. pendown or pd means pick pen down, so you can move the turtle and leave tracks.


2 Answers

Use the optional font argument to turtle.write(), from the docs:

turtle.write(arg, move=False, align="left", font=("Arial", 8, "normal"))
 Parameters:

  • arg – object to be written to the TurtleScreen
  • move – True/False
  • align – one of the strings “left”, “center” or right”
  • font – a triple (fontname, fontsize, fonttype)

So you could do something like turtle.write("messi fan", font=("Arial", 16, "normal")) to change the font size to 16 (default is 8).

like image 132
Andrew Clark Avatar answered Sep 25 '22 02:09

Andrew Clark


You can also use "bold" and "italic" instead of "normal" here. "Verdana" can be used for fontname..

But another question is this: How do you set the color of the text You write?

Answer: You use the turtle.color() method or turtle.fillcolor(), like this:

turtle.fillcolor("blue")

or just:

turtle.color("orange")

These calls must come before the turtle.write() command..

like image 22
Lars Tuff Avatar answered Sep 22 '22 02:09

Lars Tuff