对于python世界中的gui,我是一个初学者,我正在尝试为sin(x)、cos(x)、tan(x)编写一个简单的函数计算器。这是我的密码。你知道吗
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_()
我该怎么做呢?我有一个特定函数的下拉列表,但不知道如何对特定的下拉列表函数进行评估。或者我如何用x输入实际计算函数本身,并在updateUI方法中输出它。你知道吗
QComboBox's
项可以有名称和内容:以下是获取所选项目内容的方法:
请记住,在
python2
中,返回的内容包装在QVariant
;我们必须手动将其展开:因此,您的代码可能如下所示:
相关问题 更多 >
编程相关推荐