This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Tkinter font nametofont requires default root
Type: behavior Stage: resolved
Components: Tkinter Versions: Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Leonardofreua, desmondcheongzx, serhiy.storchaka, terry.reedy
Priority: normal Keywords: easy, patch

Created on 2019-01-12 21:33 by terry.reedy, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 23885 merged desmondcheongzx, 2020-12-22 05:36
Messages (4)
msg333532 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2019-01-12 21:33
font.Font.__init__, font.families, and font.names have a 'root=None' argument and start with 
    if not root:
        root = tkinter._default_root
But font.nametofont does not, and so it calls Font without passing a root argument:
     return Font(name=name, exists=True)

Font fails if there is no default root.  There cannot be one if, as recommended, one disables it.

import tkinter as tk
from tkinter import font
tk.NoDefaultRoot()
root = tk.Tk()
font.nametofont('TkFixedFont')
# AttributeError: module 'tkinter' has no attribute '_default_root'

Proposed fix: add 'root=None' parameter to nametofont (at end, to not break code) and 'root=root' to Font call.
msg383763 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-12-25 21:18
New changeset 36a779e64c580519550aa6478c5aa8c58b8fa7b6 by Desmond Cheong in branch 'master':
bpo-35728: Add root parameter to tkinter.font.nametofont() (GH-23885)
https://github.com/python/cpython/commit/36a779e64c580519550aa6478c5aa8c58b8fa7b6
msg398079 - (view) Author: Leonardo Freua (Leonardofreua) * Date: 2021-07-23 16:49
Has the PR already solved the problem? If yes, could this issue not be closed?
msg398087 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-07-23 18:47
The code I gave above now exits with a clearer message.
RuntimeError: No master specified and tkinter is configured to not support default root

But now, in 3.10, the master can be specified, so that
  fnt = font.nametofont('TkFixedFont', root)
works.  Thank you Serhiy and desmondcheongzx.
History
Date User Action Args
2022-04-11 14:59:10adminsetgithub: 79909
2021-07-23 18:47:58terry.reedysetstatus: open -> closed
resolution: fixed
messages: + msg398087

stage: patch review -> resolved
2021-07-23 16:49:21Leonardofreuasetnosy: + Leonardofreua
messages: + msg398079
2020-12-25 21:18:09serhiy.storchakasetmessages: + msg383763
2020-12-22 05:36:13desmondcheongzxsetkeywords: + patch
nosy: + desmondcheongzx

pull_requests: + pull_request22744
stage: needs patch -> patch review
2020-12-21 09:25:23serhiy.storchakasetkeywords: + easy
versions: + Python 3.10, - Python 3.8
2019-01-12 21:33:32terry.reedycreate