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

Crash message due to Lib/tkinter/font.py library (Python 3.10.x) #97961

Closed
slugspotter opened this issue Oct 6, 2022 · 2 comments
Closed

Crash message due to Lib/tkinter/font.py library (Python 3.10.x) #97961

slugspotter opened this issue Oct 6, 2022 · 2 comments
Labels
expert-tkinter type-bug An unexpected behavior, bug, or error

Comments

@slugspotter
Copy link

slugspotter commented Oct 6, 2022

This is the (useless) error message I got on Windows 10 :

File "C:\Users\Michel\Python\Textplo\textplo2_3b4v8.py", line 80, in initUI
    bold_font = font.Font(self.text, nfont)
  File "C:\Users\Michel\AppData\Local\Programs\Python\Python310\lib\tkinter\font.py", line 78, in __init__
    font = tk.splitlist(tk.call("font", "actual", font))
AttributeError: 'str' object has no attribute 'splitlist'. Did you mean: 'splitlines'?

This is the error-generating block in font.py:

        if root is None: 	#v3.10.7, line 71 ss
            root = tkinter._get_default_root('use font')
        tk = getattr(root, 'tk', root)
        print(f"root= |{root}|")	# result: root= ||

Normal working code in earlier versions:

        if not root:	#v3.7.7, line 70 ss
            root = tkinter._default_root
        tk = getattr(root, 'tk', root)
        print(f"root= |{root}|")	# result: root= |.|

(the dot in |.| stands for « main » or « root » in Tkinter)

Suggested patch : I included a modified v3.10.7 font.py (see modified block below) in a separate local directory to give it precedence and my Tkinter application now loads and runs like a charm in Python v3.10.7.

        if not root:	#my own included modified local font.py
            root = tkinter._get_default_root('use font')
        tk = getattr(root, 'tk', root)
        print(f"root= |{root}|")	# result: root= |.|

== eof ===

@slugspotter slugspotter added the type-crash A hard crash of the interpreter, possibly with a core dump label Oct 6, 2022
@ronaldoussoren ronaldoussoren added expert-tkinter type-bug An unexpected behavior, bug, or error and removed type-crash A hard crash of the interpreter, possibly with a core dump labels Oct 7, 2022
@serhiy-storchaka
Copy link
Member

I have fixed the markup and indentations in your message to make it readable.

If I understood you correctly, you suggest to use not root instead of root is None, reverting bpo-15303 in this code. The only difference between these codes is when root has a false boolean value, but not None. The error message brings us to the conclusion that it is an empty string. Looks like there is a bug in your code -- self.text is "" instead of a Text widget.

@slugspotter
Copy link
Author

slugspotter commented Oct 14, 2022

Thank you so much, Serhiy, for your quick reply.
Right on! I changed |self.text = ""| to |self.text = None|. Now, my script loads and runs well under 3.10.7.
I though that |""| was all right to initialize a text variable, but, obviously, this isn't good enough for 3.10.7.
Oddly, some other minor bugs are now showing up in my script due to an included legacy file. It looks like 3.10.7 may break older code (3.2 or 3.3). The good news is that these bugs are easy to fix thanks to the enhanced error messages of 3.10.7.

@serhiy-storchaka serhiy-storchaka closed this as not planned Won't fix, can't repro, duplicate, stale Oct 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
expert-tkinter type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants