Python - Tkinter Fonts


Advertisements

There may be up to three ways to specify type style.

Simple Tuple Fonts

As a tuple whose first element is the font family, followed by a size in points, optionally followed by a string containing one or more of the style modifiers bold, italic, underline and overstrike.

Example

  • ("Helvetica", "16") for a 16-point Helvetica regular.
  • ("Times", "24", "bold italic") for a 24-point Times bold italic.

Font object Fonts

You can create a "font object" by importing the tkFont module and using its Font class constructor −

import tkFont

font = tkFont.Font ( option, ... )

Here is the list of options −

  • family − The font family name as a string.

  • size − The font height as an integer in points. To get a font n pixels high, use -n.

  • weight − "bold" for boldface, "normal" for regular weight.

  • slant − "italic" for italic, "roman" for unslanted.

  • underline − 1 for underlined text, 0 for normal.

  • overstrike − 1 for overstruck text, 0 for normal.

Example

helv36 = tkFont.Font(family="Helvetica",size=36,weight="bold")

X Window Fonts

If you are running under the X Window System, you can use any of the X font names.

For example, the font named "-*-lucidatypewriter-medium-r-*-*-*-140-*-*-*-*-*-*" is the author's favorite fixed-width font for onscreen use. Use the xfontsel program to help you select pleasing fonts.

python_gui_programming.htm

Useful Video Courses


Video

Python Online Training

187 Lectures 17.5 hours

Malhar Lathkar

Video

Python Essentials Online Training

55 Lectures 8 hours

Arnab Chakraborty

Video

Learn Python Programming in 100 Easy Steps

136 Lectures 11 hours

In28Minutes Official

Video

Python with Data Science

Best Seller

75 Lectures 13 hours

Eduonix Learning Solutions

Video

Python 3 from scratch to become a developer in demand

Best Seller

70 Lectures 8.5 hours

Lets Kode It

Video

Python Data Science basics with Numpy, Pandas and Matplotlib

Most Popular

63 Lectures 6 hours

Abhilash Nelson

Advertisements