# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file '20200301_myWidget.ui'
#
# Created by: PyQt5 UI code generator 5.13.0
#
# WARNING! All changes made in this file will be lost!

#下面加粗字号加大的部分为固定格式,用pycharm设计ui界面,在生成的py文件中加入固定格式
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import QApplication, QWidget
class Ui_Form(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)  # 用父构造函建窗体
        # self.ui = Ui_Widget()  # UI
        self.setupUi(self)

    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(509, 384)
        self.groupBox = QtWidgets.QGroupBox(Form)
        self.groupBox.setGeometry(QtCore.QRect(10, 20, 481, 161))
        self.groupBox.setObjectName("groupBox")
        self.label = QtWidgets.QLabel(self.groupBox)
        self.label.setGeometry(QtCore.QRect(80, 20, 31, 16))
        self.label.setObjectName("label")
        self.lineEdit_sl = QtWidgets.QLineEdit(self.groupBox)
        self.lineEdit_sl.setGeometry(QtCore.QRect(110, 20, 113, 20))
        self.lineEdit_sl.setObjectName("lineEdit_sl")
        self.label_2 = QtWidgets.QLabel(self.groupBox)
        self.label_2.setGeometry(QtCore.QRect(250, 20, 31, 16))
        self.label_2.setObjectName("label_2")
        self.lineEdit_dj = QtWidgets.QLineEdit(self.groupBox)
        self.lineEdit_dj.setGeometry(QtCore.QRect(280, 20, 113, 20))
        self.lineEdit_dj.setObjectName("lineEdit_dj")
        self.lineEdit_zj = QtWidgets.QLineEdit(self.groupBox)
        self.lineEdit_zj.setGeometry(QtCore.QRect(280, 60, 113, 20))
        self.lineEdit_zj.setObjectName("lineEdit_zj")
        self.label_3 = QtWidgets.QLabel(self.groupBox)
        self.label_3.setGeometry(QtCore.QRect(250, 60, 31, 16))
        self.label_3.setObjectName("label_3")
        self.pushButton_jszj = QtWidgets.QPushButton(self.groupBox)
        self.pushButton_jszj.setGeometry(QtCore.QRect(100, 60, 75, 23))
        self.pushButton_jszj.setObjectName("pushButton_jszj")
        self.groupBox_2 = QtWidgets.QGroupBox(Form)
        self.groupBox_2.setGeometry(QtCore.QRect(10, 200, 481, 171))
        self.groupBox_2.setObjectName("groupBox_2")
        self.label_4 = QtWidgets.QLabel(self.groupBox_2)
        self.label_4.setGeometry(QtCore.QRect(30, 30, 54, 12))
        self.label_4.setObjectName("label_4")
        self.spinBox_sl = QtWidgets.QSpinBox(self.groupBox_2)
        self.spinBox_sl.setGeometry(QtCore.QRect(60, 25, 61, 22))
        self.spinBox_sl.setObjectName("spinBox_sl")
        self.label_5 = QtWidgets.QLabel(self.groupBox_2)
        self.label_5.setGeometry(QtCore.QRect(230, 30, 54, 12))
        self.label_5.setObjectName("label_5")
        self.doubleSpinBox_dj = QtWidgets.QDoubleSpinBox(self.groupBox_2)
        self.doubleSpinBox_dj.setGeometry(QtCore.QRect(260, 25, 91, 22))
        self.doubleSpinBox_dj.setObjectName("doubleSpinBox_dj")
        self.label_6 = QtWidgets.QLabel(self.groupBox_2)
        self.label_6.setGeometry(QtCore.QRect(150, 90, 81, 16))
        self.label_6.setObjectName("label_6")
        self.doubleSpinBox_zj = QtWidgets.QDoubleSpinBox(self.groupBox_2)
        self.doubleSpinBox_zj.setGeometry(QtCore.QRect(230, 90, 151, 22))
        self.doubleSpinBox_zj.setObjectName("doubleSpinBox_zj")

        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)
        self.pushButton_jszj.clicked.connect(self.on_caluate_zj)
        self.doubleSpinBox_dj.valueChanged[float].connect(self.on_caluste_dj_valuechange)
        self.spinBox_sl.valueChanged[int].connect(self.on_caluste_sl_valuechange)  #事件绑定代码放这里

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "Demo_3.1"))
        self.groupBox.setTitle(_translate("Form", "QlineEdit入和"))
        self.label.setText(_translate("Form", ""))
        self.label_2.setText(_translate("Form", ""))
        self.label_3.setText(_translate("Form", ""))
        self.pushButton_jszj.setText(_translate("Form", ""))
        self.groupBox_2.setTitle(_translate("Form", "Qspinbox入和"))
        self.label_4.setText(_translate("Form", ""))
        self.spinBox_sl.setSuffix(_translate("Form", "kg"))
        self.label_5.setText(_translate("Form", ""))
        self.doubleSpinBox_dj.setPrefix(_translate("Form", "$"))
        self.label_6.setText(_translate("Form", "动计"))
        self.doubleSpinBox_zj.setPrefix(_translate("Form", "$"))
    #事件处理函数,方法放这里
    #
    def on_caluate_zj(self):
        num = int(self.lineEdit_sl.text())
        price = float(self.lineEdit_dj.text())
        zj = num * price
        self.lineEdit_zj.setText('%.2f' % zj)

    # 当单,自动计
    @pyqtSlot(float)
    def on_caluste_dj_valuechange(self, dj):
        count = self.spinBox_sl.value()
        self.doubleSpinBox_zj.setValue(dj * count)

    @pyqtSlot(int)
    def on_caluste_sl_valuechange(self, count):
        dj = self.doubleSpinBox_dj.value()
        self.doubleSpinBox_zj.setValue(dj * count)


if __name__ == "__main__":  # 用于前窗体测试
    app = QApplication(sys.argv)  # GUI用程序
    form = Ui_Form()  # 建窗体
    form.show()
    sys.exit(app.exec_())

 

posted on 2020-03-12 20:29  wslk  阅读(507)  评论(0编辑  收藏  举报