I'm a beginner when it comes to GUIs in the python universe, and I'm trying to code a simple function evaluator for sin(x), cos(x), tan(x). Here is my code.
import matplotlib.pyplot as plt
import numpy as np
import sys
from PyQt4 import QtGui, QtCore
class Form(QtGui.QWidget) :
def __init__(self):
super(Form, self).__init__()
layout = QtGui.QVBoxLayout(self)
combo = QtGui.QComboBox()
combo.addItem("Sin")
combo.addItem("Cos")
combo.addItem("Tan")
parameter = QtGui.QLineEdit("np.linspace(lower,upper,dx)")
parameter.selectAll()
output = QtGui.QLineEdit("Output (Press Enter)")
output.selectAll()
layout.addWidget(combo)
layout.addWidget(parameter)
layout.addWidget(output)
self.setLayout(layout)
combo.setFocus()
self.connect(output, QtCore.SIGNAL("returnPressed()"), self.updateUI)
self.setWindowTitle("Function Evaluator")
def updateUI(self) :
x = float(self.parameter_edit.text())
f = str(eval(str(self.function_edit.text())))
self.output_edit.setText(f)
app = QtGui.QApplication(sys.argv)
form = Form()
form.show()
app.exec_()
How do I go about doing this? I have a dropdown for the specific functions, but don't really know how to do the evaluation of the function for the specific drop down function. Or how I go about actually evaluating the function itself with the x input, and having it output in my updateUI method.