Hello,
Im trying to make a simple equation solver with tkinter. Originally i built it without using classes and it worked fine however I am now trying to use a class.
from tkinter import *
import math
class RootFinder(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.grid()
self.create_widgets()
def create_widgets(self):
self.root1lbl=Label(self.outputframe, text='')
self.root1lbl.grid(row=0,column=1)
self.root2lbl=Label(self.outputframe,text='')
self.root2lbl.grid(row=0, column=4)
self.calcbutton=Button(self.inputframe, text="Calculate Roots",\
command=self.findroots())
self.calcbutton.grid(row=1, column=5, padx=20)
def findroots(self):
sqr=self.sqrcoeff.get()
xcoeff=self.xcoeff.get()
const=self.constant.get()
a=float(sqr)
b=float(xcoeff)
c=float(const)
root1=round((-b+math.sqrt(b*b-4*a*c))/(2*a),3)
root2=round((-b-math.sqrt(b*b-4*a*c))/(2*a),3)
self.root1lbl.configure(text=root1)
self.root2lbl.configure(text=root2)
app=RootFinder()
app.mainloop()
Ive only shown the widgets concerned. The problem is that it doesnt like me trying to configure the root1 and root2 labels and I really don't know why. This is the output when run:
Traceback (most recent call last):
File "C:/Python32/Programs/new class.py", line 83, in <module>
app=RootFinder()
File "C:/Python32/Programs/new class.py", line 9, in __init__
self.create_widgets()
File "C:/Python32/Programs/new class.py", line 37, in create_widgets
command=self.findroots())
File "C:/Python32/Programs/new class.py", line 80, in findroots
RootFinder.root1lbl.configure(text=root1)
AttributeError: type object 'RootFinder' has no attribute 'root1lbl'
Any help is appreciated thanks.