Skip to main content

tkFontChooser

A simple font chooser for Tkinter that allow the user to select the font family among the fonts available on his/her system. The size and style (bold, italic, underline, strikethrough) of the text can be set too.

This module contains a FontChooser class which implements the font chooser and an askfont function that displays the font chooser and returns the chosen font when the user closes the font chooser. The font is returned as a dictionary like the one returned by the function tkFont.Font.actual.

Requirements

  • Linux, Windows, Mac

  • Python 2 or 3 with tkinter + ttk (default for Windows but not for Linux)

Installation

  • Ubuntu: use the PPA ppa:j-4321-i/ppa

    $ sudo add-apt-repository ppa:j-4321-i/ppa
    $ sudo apt-get update
    $ sudo apt-get install python(3)-tkfontchooser
  • Archlinux:

    the package is available on AUR

  • With pip:

    $ pip install tkfontchooser

Example

try:
    from tkinter import Tk
    from tkinter.ttk import Style, Button, Label
except ImportError:
    from Tkinter import Tk
    from ttk import Style, Button, Label
from sys import platform
from tkfontchooser import askfont

# create main window
root = Tk()
style = Style(root)
if "win" == platform[:3]:
    style.theme_use('vista')
elif "darwin" in platform:
    style.theme_use('clam')
else:
    style.theme_use('clam')
bg = style.lookup("TLabel", "background")
root.configure(bg=bg)
label = Label(root, text='Chosen font: ')
label.pack(padx=10, pady=(10,4))

def callback():
    # open the font chooser and get the font selected by the user
    font = askfont(root)
    # font is "" if the user has cancelled
    if font:
        # spaces in the family name need to be escaped
        font['family'] = font['family'].replace(' ', '\ ')
        font_str = "%(family)s %(size)i %(weight)s %(slant)s" % font
        if font['underline']:
            font_str += ' underline'
        if font['overstrike']:
            font_str += ' overstrike'
        label.configure(font=font_str, text='Chosen font: ' + font_str.replace('\ ', ' '))

Button(root, text='Font Chooser', command=callback).pack(padx=10, pady=(4,10))
root.mainloop()

Metadata

Release files for tkfontchooser 2.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tkfontchooser 2.0.2
File Size Uploaded
tkfontchooser-2.0.2.tar.gz 20.3 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for tkfontchooser 2.0.2
File Interpreter ABI Platform
tkfontchooser-2.0.2-py3.6.egg Legacy Egg format - - Details
tkfontchooser-2.0.2-py2.py3-none-any.whl Python 2, Python 3 none any Details
tkfontchooser-2.0.2-py2.7.egg Legacy Egg format - - Details

Total release size: 57.1 kB

Release files / tkfontchooser-2.0.2.tar.gz

Download URL tkfontchooser-2.0.2.tar.gz
Size 20.3 kB
Tags Source
SHA-256 checksum
How to use checksums
867d33cfa17e0d0786c417756c8ff1975c91e53ed6d27216afb1cf3e4e208602
BLAKE2b-256 checksum
How to use checksums
883cc3dc5543e5b8551e2e3dd90e40e0b03bf62f5797f13ced241bb16b866cf9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.6

Release files / tkfontchooser-2.0.2-py3.6.egg

Download URL tkfontchooser-2.0.2-py3.6.egg
Size 14.7 kB
Tags Egg
SHA-256 checksum
How to use checksums
cf00d28b9aa65e9967144ce6f39a4b037e021da90164464148dca76d9f94059d
BLAKE2b-256 checksum
How to use checksums
cc4d49576abf24722779fca3f63994754fbea44afcc12afecc0aaeb936f4ea25
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.6

Release files / tkfontchooser-2.0.2-py2.py3-none-any.whl

Download URL tkfontchooser-2.0.2-py2.py3-none-any.whl
Size 7.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
e39c20d74597709f84cabc6f579f2b548ce9e82fe97fc02f85729cd1ab5bb7d6
BLAKE2b-256 checksum
How to use checksums
c697c46c1b87b60621271022620438afa5f6186431865b419c5eef5e31947d21
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.6

Release files / tkfontchooser-2.0.2-py2.7.egg

Download URL tkfontchooser-2.0.2-py2.7.egg
Size 14.7 kB
Tags Egg
SHA-256 checksum
How to use checksums
51bd0269c27347d4913cdd304f6ae7432032d644a039add57d86a668de458c43
BLAKE2b-256 checksum
How to use checksums
521477930b70f5484f752f96bf54bb90f6986d6a1929a09a2260c93a4c55c748
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.6

Release history Release notifications | RSS feed

This release

2.0.2 This release

4 release files

2.0.1

4 release files

2.0.0

4 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page