EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Software Development Software Development Tutorials Tkinter Tutorial Tkinter Font
 

Tkinter Font

Abhilasha Chougule
Article byAbhilasha Chougule
EDUCBA
Reviewed byRavi Rathore

Updated May 31, 2023

Tkinter Font

 

 

Introduction to Tkinter Font

In Python, a Tkinter font is a widget for styling or displaying text with various styles, sizes, and typeface variations. It includes options for normal, italic, and bold forms of the font. The Tkinter font widget encompasses properties such as size, weight, style, and slope for each character in the displayed or printed text.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

How does Tkinter Font work in Python?

Tkinter, a GUI library in Python, provides various widgets for designing web pages. Among these widgets is the font widget, which allows for applying different font styles to texts, buttons, headings, and other elements. In this article, we will see how to define this font property in Tkinter and see all the properties for the font.

Constructor

Font constructor that provides different styling options is as below:

Font thickness and font slant are part of the weight and slant styling options in the font constructor. The font thickness can be specified using values such as “normal” for the default thickness and “bold” for bold text.

  1. Font family: This is also supported for defining the different font styles such as “Times New Roman,” Courier,” Helvetica, etc. are some of the font families the developers widely use.
  2. Font size: This is another option for defining the size of the text or character for web page styling, and the size in these fonts is measured in integer points.
  3. Font underlines property: This is used for underlying the text or font for selected text, and it uses 0 and 1 values for specifying this property such as 0 is the default value where there is no underline for the font, and if we specify 1, then it shows the text will be underlined.
  4. Font strikeout options: This is one of the different options of the font where it will allow us to overstrike the selected text.

Python Tkinter has a separate module for defining the font class using the tkFont module. This module offers a convenient way to utilize the font class, which includes constructors defined as options or arguments within the font class. To use this module, the first step is to import it. Now let us see the syntax of how to declare font class using the tkFont module.

import tkFont

Now we can declare font class by assigning it to the variable, and the syntax is as shown below:

f = tkFont.Font(arguments)

The arguments, in this case, can be the same font constructor options defined above. The font class of the tkFont module implements various font methods. For instance, the cget() method retrieves font attributes, while the config(**arguments or options) method allows customization of font attributes. The copy() method creates new instances of the current font, and the families() method retrieves different font families. Additionally, the names() method provides the defined font names. In the following section, let’s explore a few examples of using the Tkinter font.

Example

Now first, let us a simple example of how font class can be used on button or label names which is provided by the tkFont module.

from Tkinter import *
import tkMessageBox
import Tkinter as t
import tkFont as f
master = t.Tk()
master.geometry("500x200")
def func():
    tkMessageBox.showinfo( "Hello Educba", "Button having Lucida with bold font and size is 20")
bfont = f.Font(family='Lucida Console', weight = 'bold', size = 20)
b1 = Button(master, text='Click me for Lucida', background='Cyan', fg='#000000', command = func)
b1['font'] = bfont
b1.pack()
def func1():
    tkMessageBox.showinfo( "Hello Educba", "Button having Courier with Italic font and size is 10")    
bfont1 = f.Font(family='Courier', slant = 'italic', size = 10)
b2 = Button(master, text='Click me for Courier ', background='Orange', fg='#07F', command = func1)
b2['font'] = bfont1
b2.pack()
master.mainloop() 

Output:

Tkinter Font

In the above program, we have written a Python program using Tkinter and tkFont module for designing web pages having different font styling using the tkFont module. In the above program, when we click the button, a message box will pop up, but that has the default font settings as we have not customized.

Conclusion

In this article, we saw various font constructor options, which are the same as the arguments for the tkFont module, which provides various font classes for styling the font of the text. In this article, we saw an example of demonstrating this font property of Tkinter.

Recommended Articles

This is a guide to Tkinter Font. Here we discuss the definition and working of Tkinter Font along with examples and code implementation. You may also have a look at the following articles to learn more –

  1. Tkinter LabelFrame
  2. Tkinter Menu
  3. Tkinter Listbox
  4. Tkinter Spinbox

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW