How to fix the error 'NoneType' object has no attribute 'get'?

0 like 0 dislike
15 views
If you run the code and click "Calculate" gives an error - line 30, in calculate
a = self.a.get()
AttributeError: 'NoneType' object has no attribute 'get'
Can you please explain what's the problem?
Thanks in advance.
from tkinter import* from math import sqrt class App(Frame): def __init__(self, master): super(App, self).__init__(master) self.grid() self.create_widgets() def create_widgets(self): Label(self,text = 'Coefficient a').grid(row = 0, column = 0) self.a = Entry(self).grid(row = 0, column = 1, sticky = W) Label(self,text = 'Coefficient b').grid(row = 1, column = 0) self.b = Entry(self).grid(row = 1, column = 1, sticky = W) Label(self,text = 'c Factor').grid(row = 2, column = 0) self.c = Entry(self).grid(row = 2, column = 1, sticky = W) Button(self, text = "Calculate", command = self.calculate).grid(row = 3, column = 0) Button(self, text = 'Exit', command = self.quit).grid(row = 4, column = 0) self.results = Text(self, width = 40, height = 5, wrap = WORD) self.results.grid(row = 5, column = 0, columnspan = 2) def calculate(self): a = self.a.get() b = self.b.get() c = self.c.get() D = b**2 - 4*a*c if D < 0: message = 'No solutions' elif D > 0: x1 = (-b-sqrt(D))/(2*a) x2 = (-b+sqrt(D))/(2*a) message = 'x1 =' + str(x1) + '\' message += 'x2 =' + str(x2) elif D == 0: x = (-b)/(2*a) message = 'x = '+ str(x) self.results.delete(0,0, END) self.results.insert(0,0, message) root = Tk() root.title('quadratic equation') root.geometry('350x250') app = App(root) root.mainloop()
by | 15 views

2 Answers

0 like 0 dislike
Rewrite all the widgets in this form:
self.a = Entry(self) self.a.grid(row = 0, column = 1, sticky = W)

Grid method does not return a value.
by
0 like 0 dislike
Thank you)
by

Related questions

110,608 questions
257,186 answers
0 comments
33,866 users