www.mathinfo.
tn Programmation d’interface Graphique TP3
Projet graphique N°2 : Calcul du Plus Grand Commun Diviseur
PGCD avec interface graphique Notre mini projet consiste à créer une interface graphique avec l’outil de
création Qt Designer qui permet de saisir deux entiers A et B positifs non nuls et afficher le Plus Grand
Commun Diviseur (PGCD) en utilisant la méthode des différences
Exemples : PGCD (24,18) = PGCD (6,18) = PGCD (6,12) = PGCD (6,6) = 6
PGCD (27,90) = PGCD (27, 63) = PGCD (27, 36) = PGCD (27, 9) = PGCD (18,9) =
PGCD (9,9) = 9
nb1
nb2
effacer
calculer
res
1
www.mathinfo.tn Programmation d’interface Graphique TP3
from PyQt5.uic import loadUi
from PyQt5.QtWidgets import QApplication
def pgcd(a, b):
while not (a == b):
if a > b:
a = a - b
else:
b = b - a
return a
def play():
nb1 = windows.nb1.text()
nb2 = windows.nb2.text()
if not (nb1.isdecimal()) or not (int(nb1) > 0):
windows.res.setText('Verifier nb1')
elif not (nb2.isdecimal()) or not (int(nb2) > 0):
windows.res.setText('Verifier nb2')
else:
nb1 = int(nb1)
nb2 = int(nb2)
s = pgcd(nb1, nb2)
windows.res.setText('PGCD= ' + str(s))
def effacer():
windows.nb1.clear()
windows.nb2.clear()
app = QApplication([])
windows = loadUi("pgcd.ui")
windows.show()
windows.calculer.clicked.connect(play)
windows.effacer.clicked.connect(effacer)
app.exec_()