O'Reilly logo

Tkinter GUI Application Development Blueprints - Second Edition by Bhaskar Chaudhary

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Finer control over font

In addition to the aforementioned method of handling fonts, Tkinter provides a separate Font class implementation. The source code for this class is located in the same folder as the source code for Tkinter.

On my Linux machine, the source code is located in /usr/local/lib/python3.6/tkinter/font.py. On Windows (with a default Python 3.6 install) the location is C:\Program Files (x86)\Python36-32\Lib\tkinter\font.py.

To use this module, you need to import fonts into your namespace, as follows (see the 10.08_font_demo.py code):

from tkinter import Tk, Label, Packfrom tkinter import fontroot = Tk()label = Label(root, text="Humpty Dumpty was pushed")label.pack()current_font = font.Font(font=label['font'])print ('Actual ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required