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
| # -*- coding: utf-8 -*-
# Python 3, PyQt5
import sys
from PyQt5 import (QtWidgets, QtGui, QtCore)
#############################################################################
class Fenetre(QtWidgets.QWidget):
#========================================================================
def __init__(self, parent=None):
super().__init__(parent)
self.resize(300, 200)
# crée le validator qui n'accepte que les entiers >=0 5 chiffres maxi
validator = QtGui.QIntValidator(0, 99999, self)
self.edit = QtWidgets.QLineEdit(self)
self.edit.setValidator(validator)
self.edit2 = QtWidgets.QLineEdit(self)
self.edit2.setValidator(validator)
self.bouton = QtWidgets.QPushButton("Cliquez pour afficher!", self)
self.bouton.clicked.connect(self.affiche)
# place le widget dans la fenêtre
posit = QtWidgets.QGridLayout()
posit.addWidget(self.edit, 0, 0)
posit.addWidget(self.edit2, 1, 0)
posit.addWidget(self.bouton, 2, 0)
self.setLayout(posit)
#========================================================================
def affiche(self):
n = 12345
self.edit2.setText(str(n))
#############################################################################
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
fen = Fenetre()
fen.show()
sys.exit(app.exec_()) |
Partager