简体   繁体   中英

Is there a way to import downloaded fonts into Tkinter to use it in my Python project?

I want to use a download font in Tkinter for my Python project, I read a few answers on another post but my pyglet module won't work, is there an alternative way to use my font

This worked for me (with Pycharm's pyglet library) and can be used to add downloaded fonts to Tkinter (but once again your platform must support the pyglet module):

import tkinter as tk
import pyglet

# replace 'font.ttf' with your ttf file 
pyglet.font.add_file('font.ttf')

root = tk.Tk()

# replace 'font' with your font name
MyLabel = tk.Label(root, text="font test", font=('font', 15))

MyLabel.pack()
root.mainloop()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM