Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tkinter font nametofont requires default root #79909

Closed
terryjreedy opened this issue Jan 12, 2019 · 4 comments
Closed

Tkinter font nametofont requires default root #79909

terryjreedy opened this issue Jan 12, 2019 · 4 comments
Labels
3.10 only security fixes easy topic-tkinter type-bug An unexpected behavior, bug, or error

Comments

@terryjreedy
Copy link
Member

BPO 35728
Nosy @terryjreedy, @serhiy-storchaka, @desmondcheongzx, @Leonardofreua
PRs
  • bpo-35728: Add root parameter to tkinter.font.nametofont() #23885
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-07-23.18:47:58.276>
    created_at = <Date 2019-01-12.21:33:32.069>
    labels = ['easy', 'type-bug', 'expert-tkinter', '3.10']
    title = 'Tkinter font nametofont requires default root'
    updated_at = <Date 2021-07-23.18:47:58.276>
    user = 'https://github.com/terryjreedy'

    bugs.python.org fields:

    activity = <Date 2021-07-23.18:47:58.276>
    actor = 'terry.reedy'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-07-23.18:47:58.276>
    closer = 'terry.reedy'
    components = ['Tkinter']
    creation = <Date 2019-01-12.21:33:32.069>
    creator = 'terry.reedy'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 35728
    keywords = ['patch', 'easy']
    message_count = 4.0
    messages = ['333532', '383763', '398079', '398087']
    nosy_count = 4.0
    nosy_names = ['terry.reedy', 'serhiy.storchaka', 'desmondcheongzx', 'Leonardofreua']
    pr_nums = ['23885']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue35728'
    versions = ['Python 3.10']

    @terryjreedy
    Copy link
    Member Author

    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.

    @terryjreedy terryjreedy added 3.8 only security fixes topic-tkinter type-bug An unexpected behavior, bug, or error labels Jan 12, 2019
    @serhiy-storchaka serhiy-storchaka added easy 3.10 only security fixes and removed 3.8 only security fixes labels Dec 21, 2020
    @serhiy-storchaka
    Copy link
    Member

    New changeset 36a779e by Desmond Cheong in branch 'master':
    bpo-35728: Add root parameter to tkinter.font.nametofont() (GH-23885)
    36a779e

    @Leonardofreua
    Copy link
    Mannequin

    Leonardofreua mannequin commented Jul 23, 2021

    Has the PR already solved the problem? If yes, could this issue not be closed?

    @terryjreedy
    Copy link
    Member Author

    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.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.10 only security fixes easy topic-tkinter type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants