On se propose de construire dans ce tutoriel pratique une mini application PyQt5 Avec Qt Designer qui demande à l'utilisateur de saisir un entier N et de lui renvoyer son double 2*N en cliquant sur le bouton Validate:
Solution Vidéo
Code source de l'application
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Form(object): def action(self): N = int(self.lineEdit.text()) N2 = 2*N self.lineEdit_2.setText(str(N2)) def setupUi(self, Form): Form.setObjectName("Form") Form.resize(400, 300) self.label = QtWidgets.QLabel(Form) self.label.setGeometry(QtCore.QRect(20, 30, 151, 31)) font = QtGui.QFont() font.setPointSize(16) font.setBold(True) font.setWeight(75) self.label.setFont(font) self.label.setStyleSheet("color: rgb(0, 0, 255);") self.label.setObjectName("label") self.label_2 = QtWidgets.QLabel(Form) self.label_2.setGeometry(QtCore.QRect(20, 80, 151, 31)) font = QtGui.QFont() font.setPointSize(16) font.setBold(True) font.setWeight(75) self.label_2.setFont(font) self.label_2.setStyleSheet("color: rgb(0, 0, 255);") self.label_2.setObjectName("label_2") self.lineEdit = QtWidgets.QLineEdit(Form) self.lineEdit.setGeometry(QtCore.QRect(170, 29, 191, 31)) font = QtGui.QFont() font.setPointSize(16) font.setBold(True) font.setWeight(75) self.lineEdit.setFont(font) self.lineEdit.setStyleSheet("color: rgb(255, 0, 0);") self.lineEdit.setObjectName("lineEdit") self.lineEdit_2 = QtWidgets.QLineEdit(Form) self.lineEdit_2.setGeometry(QtCore.QRect(170, 80, 191, 31)) font = QtGui.QFont() font.setPointSize(16) font.setBold(True) font.setWeight(75) self.lineEdit_2.setFont(font) self.lineEdit_2.setStyleSheet("color: rgb(255, 0, 0);") self.lineEdit_2.setObjectName("lineEdit_2") self.pushButton = QtWidgets.QPushButton(Form) self.pushButton.clicked.connect(self.action) self.pushButton.setGeometry(QtCore.QRect(170, 132, 181, 31)) font = QtGui.QFont() font.setPointSize(16) font.setBold(True) font.setWeight(75) self.pushButton.setFont(font) self.pushButton.setStyleSheet("background-color: rgb(255, 255, 0);") self.pushButton.setObjectName("pushButton") self.retranslateUi(Form) QtCore.QMetaObject.connectSlotsByName(Form) def retranslateUi(self, Form): _translate = QtCore.QCoreApplication.translate Form.setWindowTitle(_translate("Form", "Form")) self.label.setText(_translate("Form", "Value Of N :")) self.label_2.setText(_translate("Form", "Double 2*N :")) self.pushButton.setText(_translate("Form", "Validate")) if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) Form = QtWidgets.QWidget() ui = Ui_Form() ui.setupUi(Form) Form.show() sys.exit(app.exec_()) |
Younes Derfoufi
CRMEF OUJDA
1 thought on “Mini App PyQt5 Avec Qt Designer”