tkFontChooser
A simple font chooser for tkinter that allows the user to select the font family among the fonts available on his/her system. The size and style (bold, italic, underline, strike-through) of the text can be set too.
This module contains a FontSelector class which implements the font
chooser and an ask_font 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 3 with tkinter
Installation
pip install tkFontSelector
Documentation
from tkfontselector import ask_font
ask_font(master=None, text="Abcd", title="Font Chooser", **font_args)
Open the font chooser and return a dictionary of the font properties. This
dictionary is similar to the one returned by the actual method of a tkinter
Font object.
# example dictionary
{'family': str,
'size': int,
'weight': 'bold'/'normal',
'slant': 'italic'/'roman',
'underline': bool,
'overstrike': bool}
General arguments
master: Tk, Toplevel, or None (Optional)
text: str (Optional) text to show in the font selection window
title: str (Optional) changes the title of the window
fixed_only: (bool, None) (Optional), if set to True will display mono spaced fonts only, if set to False will only show regular fonts, if set to None will show everything
families_only: bool (Optional), if set to True will only show Font Families part of the UI
font_dict: dict (Optional) font dictionary like an actual Font object
**kwargs: (Optional) pass any other args that might be accepted
Font Arguments
family: str
size: int
slant: str (roman or italic)
weight: str (normal or bold)
underline: bool
overstrike: bool
Example
EXAMPLE_FONT_FAMILY = {
"family": "Comic Sans MS",
"size": 10,
"weight": "normal",
"slant": "roman",
"underline": 0,
"overstrike": 0,
}
if __name__ == "__main__":
"""Example Usage"""
root = Tk()
style = ttk.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 = ttk.Label(root, text="Chosen font: ")
label.pack(padx=10, pady=(10, 4))
def callback():
font = ask_font(root, title="Choose a font", font_args=EXAMPLE_FONT_FAMILY)
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("\ ", " ")
)
ttk.Button(root, text="Font Selector", command=callback).pack(padx=10, pady=(4, 10))
root.mainloop()
Metadata
Release files for tkfontselector 1.0.11
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tkfontselector-1.0.11.tar.gz | 9.5 kB | Without provenance | Details for tkfontselector-1.0.11.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tkfontselector-1.0.11-py3-none-any.whl | Python 3 | none | any | Details for tkfontselector-1.0.11-py3-none-any.whl |
Total release size: 19.4 kB
Release files / tkfontselector-1.0.11.tar.gz
| Download URL | tkfontselector-1.0.11.tar.gz |
|---|---|
| Size | 9.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b6cdf73d1646d263e36c737672d9a9813e8b69fe6fcb8b97334a2bea5252c82e
|
|
BLAKE2b-256 checksum How to use checksums |
036f6a987f56e2784069c8aa816d68f19b965973f17cc94dc5d8456a42bf9f5e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.11.9 Windows/10
|
Release files / tkfontselector-1.0.11-py3-none-any.whl
| Download URL | tkfontselector-1.0.11-py3-none-any.whl |
|---|---|
| Size | 10.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
21879c91a12c9896860d8762223d609359d4a214d2793aaf2f9e48051554694c
|
|
BLAKE2b-256 checksum How to use checksums |
e0aca8ec03110477775a47363e50dc6d04d3259d7c8037a54ed98dd4efa60010
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.11.9 Windows/10
|
Security for tkfontselector 1.0.11
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.