deepak
deepak

Reputation: 186

No attribute "call" error in tkinter font

I am devoloping one desktop application using tkinter . Setting font raising exception .

tmp.py

def main(root):
    frame = Frame(root.master)
    font = Font(size=25 , weight="bold")
    label = Label(frame , font=font , text="tuna fish")
    label.pack()
    frame.pack()

this is driver program main.py main.py

if __name__ == "__main__":
    root = start.baseApp()
    root.Menu_Customer.add_command(label="New customer", command=lambda: tmp.main(root=root))
    root.master.mainloop()

baseApp

i have created root window and menu bar with name Customer and added menu item New customer in main.py.
i am getting the exception in tmp.pysaying

Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib64/python3.5/tkinter/__init__.py", line 1559, in __call__
    return self.func(*args)
  File "main.py", line 10, in <lambda>
    root.Menu_Customer.add_command(label="New customer", command=lambda: tmp.main(root=root))
  File "/home/engle/Documents/Project/CleanMaster/tmp.py", line 6, in main
    font = Font(size=25 , weight="bold")
  File "/usr/lib64/python3.5/tkinter/font.py", line 93, in __init__
    tk.call("font", "create", self.name, *font)
AttributeError: 'NoneType' object has no attribute 'call'


whats wrong with it ?

Upvotes: 6

Views: 3241

Answers (1)

Josselin
Josselin

Reputation: 2643

In order to work with the Font class in tkinter, an instance of Tk() must be running. If you have such an instance running, try to explicitly pass it as argument to your font:

def main(root):
    ...
    font = Font(root=root.master, size=25 , weight="bold")
    ...

Upvotes: 6

Related Questions