我正在开发PyQt5桌面GUI应用程序,允许用户通过将所选值连接到lineEdit中所需的输入以及从结果中选择的内容,从组合框中选择选项。 combobox将在resultlineEdit中输出其结果,请提供任何帮助。谢谢。
我尝试了几种代码,但似乎它们的语法不对应。下面是我的代码。
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def event(self):
# get value of the selected combobox data
#conditions
#if a is given, use this formulars
b = 5 + a
#if b is given,
a = 4 - b
#set the selected combobox result in the reversed
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(372, 207)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.calcbtn = QtWidgets.QPushButton(self.centralwidget)
self.calcbtn.setGeometry(QtCore.QRect(20, 120, 75, 23))
self.calcbtn.setObjectName("calcbtn")
##########################################################
self.calcbtn.clicked.connect(self.event)
#########################################################
self.line = QtWidgets.QFrame(self.centralwidget)
self.line.setGeometry(QtCore.QRect(0, 150, 371, 16))
self.line.setFrameShape(QtWidgets.QFrame.HLine)
self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line.setObjectName("line")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(10, 160, 47, 13))
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(10, 40, 47, 13))
self.label_2.setObjectName("label_2")
self.inputcomboBox = QtWidgets.QComboBox(self.centralwidget)
self.inputcomboBox.setGeometry(QtCore.QRect(20, 60, 69, 22))
self.inputcomboBox.setObjectName("inputcomboBox")
self.inputcomboBox.addItem("")
self.inputcomboBox.addItem("")
self.inputLineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.inputLineEdit.setGeometry(QtCore.QRect(100, 60, 113, 20))
self.inputLineEdit.setObjectName("inputLineEdit")
self.resultLineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.resultLineEdit.setGeometry(QtCore.QRect(110, 180, 113, 20))
self.resultLineEdit.setObjectName("resultLineEdit")
self.resultcomboBox = QtWidgets.QComboBox(self.centralwidget)
self.resultcomboBox.setGeometry(QtCore.QRect(30, 180, 69, 22))
self.resultcomboBox.setObjectName("resultcomboBox")
self.resultcomboBox.addItem("")
self.resultcomboBox.addItem("")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(130, 120, 47, 13))
self.label_3.setObjectName("label_3")
self.label_4 = QtWidgets.QLabel(self.centralwidget)
self.label_4.setGeometry(QtCore.QRect(130, 140, 47, 13))
self.label_4.setObjectName("label_4")
self.label_5 = QtWidgets.QLabel(self.centralwidget)
self.label_5.setGeometry(QtCore.QRect(10, 10, 81, 16))
self.label_5.setObjectName("label_5")
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "CALC"))
self.calcbtn.setText(_translate("MainWindow", "SOLVE"))
self.label.setText(_translate("MainWindow", "RESULTS"))
self.label_2.setText(_translate("MainWindow", "INPUT"))
self.inputcomboBox.setItemText(0, _translate("MainWindow", "a"))
self.inputcomboBox.setItemText(1, _translate("MainWindow", "b"))
self.resultcomboBox.setItemText(0, _translate("MainWindow", "a"))
self.resultcomboBox.setItemText(1, _translate("MainWindow", "b"))
self.label_3.setText(_translate("MainWindow", "a = 4 - b"))
self.label_4.setText(_translate("MainWindow", "b = 5 + a"))
self.label_5.setText(_translate("MainWindow", "CALCULATION"))
if __name__ == "__main__":
import sys[enter image description here][1]
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
我希望当我单击“计算”按钮时,应该可以解决计算问题