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

Created on 2019-01-12 21:33 by terry.reedy, last changed 2020-12-25 21:18 by serhiy.storchaka.

Pull Requests
URL Status Linked Edit
PR 23885 merged desmondcheongzx, 2020-12-22 05:36
Messages (2)
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
root = tk.Tk()
# 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)
Date User Action Args
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