# L-31 MCS 260 Wed 30 Mar 2016 : guieval.py
"""
GUI to evaluation a user given function.
"""
from tkinter import Tk, Label, Entry, Button
from tkinter import END, INSERT
from math import cos, sin

TOP = Tk()
TOP.title("Evaluate Expressions")
Label(TOP, text="f(x) =").grid(row=0)
F = Entry(TOP)
F.grid(row=0, column=1)
Label(TOP, text="x =").grid(row=0, column=2)
E = Entry(TOP)
E.grid(row=0, column=3)
R = Entry(TOP)
R.grid(row=0, column=5)

def calc():
    "evaluates the function"
    R.delete(0, END)
    x = float(E.get())
    result = eval(F.get())
    R.insert(INSERT, result)

B = Button(TOP, text="equals", command=calc)
B.grid(row=0, column=4)
TOP.mainloop()
