How to get all available fonts in Tkinter

In this tutorial we are going to learn to get all available fonts in Tkinter using python code. We always search the fonts in different websites or in online but it is very time consuming process. So this code will save your time, You can get all the fonts which are available in tkinter with 10 lines of code. before starting the tutorial we first learn about Tkinter.

Tkinter Library in python:

Tkinter is a python library that is used to develop GUI (graphical user interface) apps. It is similar to the abstract window toolkit which is available in java, But however tkinter in python is more efficient than awt in java. This tkinter library consists of  inbuilt tools such as buttons, text, checkbox, combo box, radio button, etc. If you want to learn some projects of tkinter, Click this: A simple music player GUI app using Tkinter

python code to get all available fonts in Tkinter :

import tkinter as tk   # importing modules
from tkinter import Tk,font 
window=tk.Tk()    # creating a window
window.geometry("700x700") # setting window size
fontss=list(font.families()) # sending all fonts into a list
count=1
for i in fontss:
    print(count,".",i)    # printing the list
    count+=1

Output :

1 . System
2 . 8514oem
3 . Fixedsys
4 . Terminal
5 . Modern
6 . Roman
7 . Script
8 . Courier
9 . MS Serif
10 . MS Sans Serif

From the above code you can get all the  Text-Fonts. You will get almost 185-186 fonts which will print in your command prompt. You can easily copy and paste it in your font section.

Explanation of the code :

 

In this code we first import the tkinter module so that we can use necessary packages. Next we are creating a window with tk.Tk() function. Then we are setting the size of the window which is (700×700) height and width. Now we are storing the fonts in a list and further storing them in a variable fontss as fontss=list(font.families()). As all the fonts have stored in the list we can easily print them using for loop. I have taken ‘i’ pointer in the list and iterating them one by one like this :  for i in fontss . Initially i have given the count value as 1 then when ever it prints a value the count value will increment by one. Hence we even get count of the fonts. Hope this tutorial is useful to you.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top