check entry inputs in tkinter using a function
Question: I trying to create physics calculator using python tkinter but I find it quite
difficult. I have done this calculator in Command line interface but I a bit
different with tkinter. basically, I have 5 entry boxes and above each one of
them a button. the user will insert values in three of them and should press
the button on top of each unknown value to make the calculation and get the
result. my main issue is how can I create a function that evaluates the inputs
in my entry boxes and make the calculation then print the results inside the
entry box. I made some coding but unfortunately the operation is not working
due to few mistakes.

here is my coding part:

    
    
    from Tkinter import *
    import math
    
    class calculator():
    
        def is_positive_number(number): # validation function
             if number <= 0:
                 return False
             else :
                 return True
    
        def value_of_time(prompt):
            while True: # loop command for time 
                try:     
                    valid = False
                    while not valid:
                        value = float((prompt))
                        if is_positive_number(value):
                            valid = True
                            return value
                        else :
                            valid = False
                            print ('I donot know what is happening')
                except ValueError:
                    print("Oops, unfortunately this is a wrong input, please try again.")
                    #better try again... Return to the start of the loop
                    continue
                else:
                    #value was successfully parsed!
                    #we're ready to exit the loop.
                    break
    
    
        def input_of_box(prompt):
            while True: # loop for initial velocity
                try:
                    value = float(input(prompt))
                    return value
                except ValueError:
                    print("Oops, we are you not typing a number, please try again.")
                    #better try again... Return to the start of the loop
                    continue
                else:
                    #value was successfully parsed!
                    #we're ready to exit the loop.
                    break
    
    
        # def minput(numberofinput):
            if numberofinput == 1:
                t = value_of_time("Enter the time that takes an object to accelerate in seconds:")
                return 
            elif numberofinput == 2:
                u = input_of_box("Enter the initial velocity in m/s:")
                return
            elif numberofinput == 2:
                v = input_of_box("Enter the final velocity in m/s:")
                return
    
    
    
        def my_calculation(mvariables): # this function is to operate the calculation
    
            if mvariables == 1:
                a = (v-u) /(t)
                mentery1 = a
                return 
    
            elif mvariables == 2:
                v = u + a*t
                mentery2 = v
                return
            elif mvariables == 3:
                u = a*t - v
                mentery3 = t
    
            elif mvariables == 4:
                t = (v - u)/a
                mentery3 = t
                return
            elif mvariables == 5:
                s = (v**2-u**2)/2*a
                mentery4 = s
            else:
                print ('there is an error')
    
    
    
    
        cal = Tk()
        cal.configure(background='sky blue')
        a = StringVar()
        u = StringVar()
        v = StringVar()
        t = StringVar()
        s = StringVar()
    
    
        cal.geometry('650x420+350+225')
    
        cal.title('Main Menu')
    
        # here we start greating buttons and entry boxes
        m_label = Label(text='Calculator',fg = 'Navy', font=("Helvetica", 20,"bold italic"), bg='sky blue')
        m_label.pack()
    
        button1 = Button(cal,text='A',fg='white',bg='dark green',bd =3, width=4, command= lambda : my_calculation(1))
        button1.place(x=92,y=210)
    
        mentery1 = Entry(cal, textvariable = a ,width=10,bd =3)
        mentery1.place(x=82,y=240)
    
        button2 = Button(cal,text='U',fg='white',bg='dark green',bd =3, width=4, command= lambda : my_calculation(3))
        button2.place(x=192,y=210)
    
        mentery2 = Entry(cal, textvariable = u ,width=10,bd =3)
        mentery2.place(x=182,y=240)
    
        button3 = Button(cal,text='V',fg='white',bg='dark green',bd =3, width=4, command= lambda : my_calculation(2))
        button3.place(x=292,y=210)
    
        mentery3 = Entry(cal, textvariable = v ,width=10,bd =3)
        mentery3.place(x=282,y=240)
    
        button4 = Button(cal,text='T',fg='white',bg='dark green',bd =3, width=4,command= lambda : my_calculation(4))
        button4.place(x=392,y=210)
    
        mentery4 = Entry(cal, textvariable = t ,width=10,bd =3)
        mentery4.place(x=382,y=240)
    
        button5 = Button(cal,text='S',fg='white',bg='dark green',bd =3, width=4,command= lambda : my_calculation(5))
        button5.place(x=492,y=210)
    
        mentery5 = Entry(cal, textvariable = s , width=10,bd =3)
        mentery5.place(x=482,y=240)
        # end of button commands
    
    app = calculator()
    app.mainloop()
    


Answer: For validating the input, do the following:

    
    
    def returnValidatedInput(entry):
        value = entry.get() # Get the text in the 'entry' widget
        evaluation = eval(value) # Evaluate 'value'
        return evaluation
    

And for inserting the answers into the entries (it's not called _printing the
answers into the entries_):

    
    
    def insertAnswer(entry, answer):
        entry.delete(0, 'end') # Be sure the entry is empty, if it is not, clear it
        entry.insert(END, str(answer)) # Insert the answer into the 'entry' widget.
    

