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.py
saying
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 ?
Running the above code will set the default font as "lucida 20 bold italic" for all the widgets that uses textual information.
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")
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With