Pyglet working only with installed fonts?

Question:

This program uses Tkinter and I’m trying to display text using a custom font that is not installed on my Windows machine, since other users certainly will not have this font installed as well..

I’ve tried to use pyglet but it only works when the font is installed..
Here it is a quick example:

import tkinter as tk, pyglet

pyglet.font.add_file('digital-7.ttf') #font file is in the same folder of this python script.
root = tk.Tk()

MyLabel = tk.Label(root, text="EXAMPLE TEXT", font=('Digital-7', 25)) #font family name is correct.
MyLabel.pack()


root.mainloop()

I’ve tried using the same font installed and uninstalled on my machine, the result was achieved only when the font was installed..

Someone knows what I’m doing wrong? Because I’m not getting any errors so I don’t know what to do..
I’m using Python 3.11 on a Windows 10 machine..

Also, if someone knows other ways of using downloaded fonts without having to install them, it will help me as well, even if it has to use Kivy, PyQt etc..

Thank you everyone in advance..

Asked By: Marcos V. Santos

||

Answers:

From version 2.0.0, pyglet.font.directwrite.Win32DirectWriteFont class is used instead of pyglet.font.win32.GDIPlusFont class and the former seems not working.

Either using older version like 1.5.27 or force using GDIPlusFont by setting pyglet.options['win32_gdi_font'] = True right after importing pyglet:

import tkinter as tk
import pyglet
pyglet.options['win32_gdi_font'] = True

pyglet.font.add_file('digital-7.ttf')

root = tk.Tk()

MyLabel = tk.Label(root, text="EXAMPLE TEXT", font=('Digital-7', 25)) #font family name is correct.
MyLabel.pack()

root.mainloop()

Result:

enter image description here

Answered By: acw1668