Python Stringvar instance has no __trunc__method
Question: For fun (and to learn...), I'm trying to write a program that takes 3 inputs,
a, b and c, and returns the solution to the quadratic formula. Right now, I'm
getting an error saying StringVar instance has no attribute '**trunc** ' I
initially had my entry variables set up as IntVar and got the same type of
error, with IntVar instance not having the **trunc** attribute.

    
    
    import Tkinter
    from math import *
    
    
    def quadprogram(a,b,c):
    
        x1=((-1*int(b)+(sqrt((int(b)**2)-(4*int(a)*int(c))))/2*int(a)))
        x2=((-1*int(b)-(sqrt((int(b)**2)-(4*int(a)*int(c))))/2*int(a)))
    
        my_answer="(x+"+str(-1*x1)+")(x+"+str(-1*x2)+")"
        xinputs= "x1= "+ str(x1) + " and x2= "+str(x2)
        answers= my_answer+", "+ xinputs
        return answers
    
    class quadratic(Tkinter.Tk):
        def __init__(self,parent):
            Tkinter.Tk.__init__(self,parent)
            self.parent=parent
            self.initialize()
    
        def initialize(self):
            self.grid()
    
            self.entryVariableA = Tkinter.StringVar()
            self.entry= Tkinter.Entry(self, textvariable= self.entryVariableA)
            self.entry.grid(column=0,row=2,sticky="W")
            self.entry.bind("<Return>",self.OnPressEnter)
            self.entryVariableA.set(u"a")
    
            self.entryVariableB = Tkinter.StringVar()
            self.entry= Tkinter.Entry(self, textvariable= self.entryVariableB)
            self.entry.grid(column=0,row=3,sticky="W")
            self.entry.bind("<Return>",self.OnPressEnter)
            self.entryVariableB.set(u"b")
    
            self.entryVariableC = Tkinter.StringVar()
            self.entry= Tkinter.Entry(self, textvariable= self.entryVariableC)
            self.entry.grid(column=0,row=4,sticky="W")
            self.entry.bind("<Return>",self.OnPressEnter)
            self.entryVariableC.set(u"c")
    
    
    
    
            button = Tkinter.Button(self, text= u"Solve!", command=self.OnButtonClick)
            button.grid(column=1,row=5)
    
            self.labelVariable= Tkinter.StringVar()
            self.Eq_labelVariable=Tkinter.StringVar()
            self.Ans_labelVariable=Tkinter.StringVar()
    
            label= Tkinter.Label(self, textvariable=self.labelVariable,anchor= 'w', fg='black',bg='blue')
            label.grid(column=0,row=0, columnspan=2, sticky='EW')
            self.labelVariable.set(u"Enter Equation Here...")
    
            Eq_label=Tkinter.Label(self, textvariable=self.Eq_labelVariable,anchor='w', fg='white', bg='blue')
            Eq_label.grid(column=0, row=1, columnspan=2, sticky='EW')
            self.Eq_labelVariable.set(u"For A(x^2)+B(x)+C")
    
            Ans_label=Tkinter.Label(self, textvariable=self.Ans_labelVariable,anchor='w', fg='black', bg='green')
            Ans_label.grid(column=0, row=1, columnspan=2, sticky='EW')
            self.Ans_labelVariable.set(u"Answer will show here")
    
    
            self.grid_columnconfigure(0,weight=1)
            self.resizable(True, False)
            self.update()
            self.geometry(self.geometry())
            self.entry.focus_set()
            self.entry.selection_range(0,Tkinter.END)
    
    
    
        def OnButtonClick(self):
            self.Ans_labelVariable.set(quadprogram(self.entryVariableA,self.entryVariableB,self.entryVariableC)+"(this program works?!)")
            self.entry.focus_set()
            self.entry.selection_range(0, Tkinter.END)
    
        def OnPressEnter(self,event):
            self.labelVariable.set(self.entryVariableA.get())
    
    
    if __name__=='__main__':
        app=quadratic(None)
        app.title("Quadratic Solver")
        app.geometry("300x300")
        app.mainloop()
    

Anyone have any thoughts on avoiding that? Thanks for the help...


Answer: Everything is being initialized when you create the class, including whichever
values are in your entry widgets. Make methods to retrieve the values in the
entry widgets, and keep those methods out of your initialization. I will
update answer with code in a few minutes.

