In normal development, we often need to come into contact with situations such as signals and slot functions. Today, let's learn about information and slot functions together.
First look at the layout
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Calc (object) :
def setupUi (self, form) :
self.inputSpinBox1 = QtWidgets.SQpinBox(Form)
self.inputSpinBox1.setGeometry(QtCore.QRect(1 ,26 , 46 , 25 ))
self.inputSpinBox1.setObjectName("inputSpinBox1" )
self.inputSpinBox2 = QtWidgets.QSpinBox(Form)
self.inputSpinBox2.setGeometry(QtCore.QRect(70 , 26 , 46 , 25 ))
self.inputSpinBox2.setObjectName("inputSpinBox2" )
self.outputWidget = QtWidget.QLabel(Form)
self.outputWidget.setgeometry(QtCore.QRect(140 , 24 , 36 ,27 ))
self.outputWidget.setObjectname("outputWidget" )
QtCore.QMetaObject.connectSlotByName(Form)
This is the front-end logic interface
import sys
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import QApplication, QWidget
from ui_calc import Ui_Calc
class MyCalc (QWidget) :
def __init__ (self, parent=None) :
super().__init__(parent)
self.ui = Ui_Calc()
self.ui.setupUi(self)
@pyqtSlot(int)
def on_inputSpinBox1_valueChanged (self, value) :
self.ui.outputWidget.setText(str(value+self.ui.inputSpinBox2.value()))
@pyqtSlot(int)
def on_inputSpinBox2_valueChanged (self, value) :
self.ui.outputWidget.setText(str(value+self.ui.inputSpinBox2.value))
if __name__ == '__main__' :
app = QApplication(sys.argv)
win = MyCalc()
win.show()
sys.exit(app.exec_())