![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use a custom font in Tkinter?
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.
Example
#Import the required library from tkinter import * #Create an instance of tkinter frame win = Tk() win.geometry("750x250") #Create a String Object and set the default value var = StringVar() #Create a text label label = Label(win, textvariable = var, font=('Consolas 20 bold')) label.pack() #Create an entry widget to change the variable value text = Entry(win, textvariable = var) text.pack() win.mainloop()
Output
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.
Advertisements