1

This one is pretty straightforward. How can I get a turtle.Turtle() to write in a custom font saved in the same folder? I've looked all over but have found no real answer. Thanks in advance!

cdlane
  • 40,441
  • 5
  • 32
  • 81
Donoru
  • 115
  • 1
  • 15

1 Answers1

3

Here's what I did just now on OSX:

  • Downloaded the TTF Pacifico font from FontSquirrel.com (just a random choice.)

  • Via the Finder, opened the 'pacifico' folder in Downloads

  • Clicked on Pacifico.ttf which caused this panel to open:

enter image description here

  • Selected Install Font on this panel. After a few tries, got the Font Validation panel in Font Book:

enter image description here

  • Clicked on the font check box (or 'Select all fonts') and then pressed Install Checked. After a few tries, including possibly logging out and logging in again, I was able to run the following:
from turtle import Screen, Turtle

screen = Screen()
turtle = Turtle()

turtle.write("Pacifico Font", align='center', font=('Pacifico', 48))

screen.mainloop()
  • Which produced the window:

enter image description here

  • Which to my surprise, actually worked!

Python turtle is built atop tkinter, so the question is:
"How can I use custom local fonts in Python tkinter?"

My understanding is there is no single answer, as tkinter depends on the operating system for fonts. So my solution was to install the font.

In the OSX case, the above steps installed it as a 'User' (personal) font,
which I could remove once finished with it.

Red
  • 26,798
  • 7
  • 36
  • 58
cdlane
  • 40,441
  • 5
  • 32
  • 81
  • Thanks so much! I tried installing the font and even on Windows it worked! You are truly amazing, as this is for a Turtle game jam. I finished the game, and you responded just in time! Now I can just replace all the Arial's with Pixel! – Donoru Jun 28 '20 at 23:32