我正在写一个重量转换器将killogram转换为Pounds,反之亦然.... 使用QT Desginer我已经完成了界面等,但现在我不知道如何找出如何链接按钮,这样当你按下它时它会转换为磅输入的内容,反之亦然...
编码到目前为止:
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(486, 406)
self.pushButton = QtWidgets.QPushButton(MainWindow)
self.pushButton.setGeometry(QtCore.QRect(160, 320, 151, 41))
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(MainWindow)
self.pushButton_2.setGeometry(QtCore.QRect(160, 60, 151, 41))
self.pushButton_2.setObjectName("pushButton_2")
self.label = QtWidgets.QLabel(MainWindow)
self.label.setGeometry(QtCore.QRect(86, 20, 301, 31))
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(MainWindow)
self.label_2.setGeometry(QtCore.QRect(20, 230, 131, 21))
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(MainWindow)
self.label_3.setGeometry(QtCore.QRect(350, 230, 111, 21))
self.label_3.setObjectName("label_3")
self.lineEdit = QtWidgets.QLineEdit(MainWindow)
self.lineEdit.setGeometry(QtCore.QRect(20, 170, 113, 41))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit_2 = QtWidgets.QLineEdit(MainWindow)
self.lineEdit_2.setGeometry(QtCore.QRect(340, 170, 113, 41))
self.lineEdit_2.setObjectName("lineEdit_2")
self.label_4 = QtWidgets.QLabel(MainWindow)
self.label_4.setGeometry(QtCore.QRect(10, 60, 441, 311))
self.label_4.setToolTipDuration(2)
self.label_4.setText("leh")
self.label_4.setPixmap(QtGui.QPixmap("../../../../../Desktop/unbalanced-
scale.png"))
self.label_4.setIndent(-4)
self.label_4.setObjectName("label_4")
self.label_4.raise_()
self.pushButton.raise_()
self.pushButton_2.raise_()
self.label.raise_()
self.label_2.raise_()
self.label_3.raise_()
self.lineEdit.raise_()
self.lineEdit_2.raise_()
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Main Window"))
self.pushButton.setText(_translate("MainWindow", "<<< Pounds to Killogram"))
self.pushButton_2.setText(_translate("MainWindow", "Killogram to Pounds >>>"))
self.label.setText(_translate("MainWindow", " Welcom to PJ Nothnagel\'s Weight Converter!"))
self.label_2.setText(_translate("MainWindow", " Killograms"))
self.label_3.setText(_translate("MainWindow", " Pounds"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QDialog()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())