tkinter - How to set font for Text? tkinter - How to set font for Text? tkinter tkinter

tkinter - How to set font for Text?


When specifying fonts in this manner, use a tuple:

text.configure(font=("Times New Roman", 12, "bold"))

Even better, you can create your own custom font objects and specify the attributes by name. Note: before you can create a font object you must first create a root window.

# python 2# import Tkinter as tk# from tkFont import Font# python 3import tkinter as tkfrom tkinter.font import Fontroot = tk.Tk()text = tk.Text(root)...myFont = Font(family="Times New Roman", size=12)text.configure(font=myFont)

The advantage to creating your own fonts is that you can later change any attribute of the font, and every widget that uses that font will automatically be updated.

myFont.configure(size=14)