Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Downloaded Fonts To Tkinter

I want to download an open source font and use it in my Python Tkinter Program.

How can I tell Tkinter to import a font from a directory or by putting the font in the same folder as the program ?

Note: I have searched for an answer for a while even reading API reference of Tkinter about every font related thing I could find. If there was an obvious answer to this question and I didn't know because maybe I didn't search hard enough or asked the wrong questions I am sorry.

like image 232
Buğra Coşkun Avatar asked Aug 07 '16 15:08

Buğra Coşkun


People also ask

How do I use downloaded fonts in Python?

Install fonts on your system. Usually, double-click on the . ttf file and then click on the Install button in the window that pops up. Note that Matplotlib handles fonts in True Type Format (.

What is from tkinter import * in Python?

In order to work with a tkinter application, we have to install and import the tkinter library in our environment. Generally, we import the tkinter library in the environment by using from tkinter import * command. The significance of "import *" represents all the functions and built-in modules in the tkinter library.


Video Answer


1 Answers

This worked for me on Windows (and I would guess on any platform which supports the pyglet module)

import tkinter as tk
import pyglet, os

pyglet.font.add_file('myFont.ttf')  # Your TTF file name here

root = tk.Tk()
MyLabel = tk.Label(root,text="test",font=('myFont',25)) 

MyLabel.pack()
root.mainloop()
like image 95
P S Solanki Avatar answered Nov 15 '22 01:11

P S Solanki