We now have a youtube channel. Subscribe!

Python Tkinter Fonts



Hello dear readers! welcome back to another section of our tutorial on Python. In this tutorial post, we are going to be discussing about Python Tkinter Fonts.

There may be up to three different ways to specify style types.

Simple Tuple Fonts

As a tuple whose first element is the font family, then 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") - This is for a 16-point Helvetica regular.
  • ("Times", "24", "bold italic") - This is 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, ... )


Font Options

Following is the list of common font options -

  • family - This is 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, and "roman" for unslanted.
  • underline - 1 for underlined text, and 0 for normal.
  • overstrike - 1 for overstruck text, and 0 for normal.

Example

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

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

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

RECOMMENDED: Python Tkinter Colors

Alright guys! This is where we are rounding up for this tutorial post. In our next tutorial, we are going to be discussing about the Python Tkinter Anchors.

Feel free to ask your questions where necessary and i will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.

Post a Comment

Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.
© 2023 ‧ WebDesignTutorialz. All rights reserved. Developed by Jago Desain