The Wayback Machine - https://web.archive.org/web/20250403044433/https://www.geeksforgeeks.org/how-to-set-font-for-text-in-tkinter/
Open In App

How to set font for Text in Tkinter?

Last Updated : 01 Apr, 2025
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Share
Report
News Follow

Tkinter allows you to customize the appearance of text in various widgets. Customizing the font helps in enhancing the readability and user experience of the application interface. Tkinter offers several ways to set fonts, whether you prefer to define a font once for reuse or specify it for individual widgets. Let’s explore different methods for customizing text fonts in Tkinter.

Using the Font Object from tkinter.font

Tkinter provides the tkinter.font.Font module, which allows you to define custom fonts with specific properties like font family, size, and weight. This approach is useful when you want to reuse the same font settings across multiple widgets.

Python
import tkinter
import tkinter.font

root = tkinter.Tk()
root.title("Font Example in Tkinter")
root.geometry("500x300")

# Create a Text widget
txt = tkinter.Text(root, height=10)
txt.pack()

# Custom font
cf = tkinter.font.Font(family="Arial", size=18, weight="bold")

txt.configure(font=cf)
root.mainloop()

Output:

Output

Using font object

Explanation: A Text widget is added to the window with a height of 10 lines for multi-line input. A custom font is created using tkinter.font.Font with the family “Arial”, size 18 and bold weight. This font is applied to the Text widget using the configure() method. The mainloop() is called to keep the window open and responsive.

Using a Tuple in .configure()

Instead of using the Font object, you can directly specify the font properties as a tuple inside the configure() method. This is a simpler approach when the font is only needed for a specific widget.

Python
import tkinter 

root = tkinter.Tk()  # Create main window
root.title("Font Example in Tkinter")
root.geometry("400x240")

txt = tkinter.Text(root, height=10)  # Create Text widget
txt.pack()

tup = ("Comic Sans MS", 20, "bold")  # Define font
txt.configure(font=tup)  # Apply font
root.mainloop() 

Output:

Output

Using configure()

Explanation: A Text widget is created in the main window with a height of 10 lines. The font is set using the tuple (“Comic Sans MS”, 20, “bold”) and applied via configure(). mainloop() keeps the window open and responsive.

Using Text Widget Directly in Constructor

Another way to define a font is by passing the font properties directly into the widget’s constructor. This eliminates the need for an extra configuration step.

Python
import tkinter

root = tkinter.Tk()  # Create main window

root.title("Font Example in Tkinter")
root.geometry("400x240")

txt = tkinter.Text(root, height=10, font=("Verdana", 18, "italic"))
txt.pack()
root.mainloop()

Output:

Output

Using text widget directly in constructor

Explanation: In this code, a Text widget is created in the main window with a height of 10 lines. The font is set directly in the widget’s constructor using the tuple (“Verdana”, 18, “italic”), which specifies the font family as “Verdana”, the size as 18, and the style as “italic”.



Next Article

Similar Reads

three90RightbarBannerImg