On Sun, 26 Feb 2017 09:17:00 +0100, Peter Otten wrote: > 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.
OK, that makes sense. I knew I was doing something dumb or in this case, not doing it. Thank you. -- <Wildman> GNU/Linux user #557453 The cow died so I don't need your bull! -- https://mail.python.org/mailman/listinfo/python-list