Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem With Tkinter Font

130 views
Skip to first unread message

Wildman

unread,
Feb 26, 2017, 2:17:06 AM2/26/17
to
Python 3.4.2
Tkinter 8.6
Linux

I want to set the font in a GUI program I am working on.
Here is the pertinent code I am using...

from tkinter import font

myfont = font.Font(family='Helvetica', size=10, weight='bold')

Here is the error I get...

Traceback (most recent call last):
File "./test.py", line 41, in <module>
myfont = font.Font(family='Helvetica', size=10, weight="bold")
File "/usr/lib/python3.4/tkinter/font.py", line 93, in __init__
tk.call("font", "create", self.name, *font)
AttributeError: 'NoneType' object has no attribute 'call'

From my research, the syntax is correct but I am having
doubts. Can anyone clarify?

--
<Wildman> GNU/Linux user #557453
The cow died so I don't need your bull!

Peter Otten

unread,
Feb 26, 2017, 3:17:33 AM2/26/17
to
Wildman via Python-list wrote:

> Python 3.4.2
> Tkinter 8.6
> Linux
>
> I want to set the font in a GUI program I am working on.
> Here is the pertinent code I am using...
>
> from tkinter import font
>
> myfont = font.Font(family='Helvetica', size=10, weight='bold')
>
> Here is the error I get...
>
> Traceback (most recent call last):
> File "./test.py", line 41, in <module>
> myfont = font.Font(family='Helvetica', size=10, weight="bold")
> File "/usr/lib/python3.4/tkinter/font.py", line 93, in __init__
> tk.call("font", "create", self.name, *font)
> AttributeError: 'NoneType' object has no attribute 'call'
>
> From my research, the syntax is correct but I am having
> doubts. Can anyone clarify?

If you do not provide the root argument there is still an implicit
dependency:

"""
class Font:
...
def __init__(self, root=None, font=None, name=None, exists=False,
**options):
if not root:
root = tkinter._default_root
tk = getattr(root, 'tk', root)

"""

>>> import tkinter
>>> from tkinter import font
>>> font.Font(family="Helpvetica", size=10, weight="bold")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.4/tkinter/font.py", line 93, in __init__
tk.call("font", "create", self.name, *font)
AttributeError: 'NoneType' object has no attribute 'call'
>>> root = tkinter.Tk()
>>> font.Font(family="Helpvetica", size=10, weight="bold")
<tkinter.font.Font object at 0x7fb9fdfdb6d8>

So you have to create the main window before you can create a Font.

Wildman

unread,
Feb 26, 2017, 10:36:11 AM2/26/17
to
OK, that makes sense. I knew I was doing something dumb
or in this case, not doing it. Thank you.
0 new messages