How to use a custom font in Tkinter?

TkinterServer Side ProgrammingProgramming

To define and display a custom font in Python tkinter, we generally use an inbuilt font library defined in tkinter. In order to import the tkinter Font library in the notebook, type the following in the shell,

from tkinter.font import Font

Now, create an Object of Font using the Font(..options) function and define other properties of the font such as font-family, size, weight, slant, underline, strike, etc.


#Import the required library
from tkinter import *
#Create an instance of tkinter frame
win = Tk()
#Create a String Object and set the default value
var = StringVar()
#Create a text label
label = Label(win, textvariable = var, font=('Consolas 20 bold'))
#Create an entry widget to change the variable value
text = Entry(win, textvariable = var)


Running the above code will display a window with an Entry widget and a Label. The Label gets updated whenever we enter some keywords in the Text Field.

Updated on 16-Apr-2021 07:05:03