Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 248
deepak Avatar asked Aug 16 '17 05:08

deepak


People also ask

What is tkinter label default font?

Running the above code will set the default font as "lucida 20 bold italic" for all the widgets that uses textual information.


1 Answers

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")
    ...
like image 118
Josselin Avatar answered Oct 02 '22 05:10

Josselin