Correction Tp2 Qt Designer Python 1
Correction Tp2 Qt Designer Python 1
Correction TP2
Qt designer, Pyqt5 et Python
Nombre parfait :
pgr0.py
def parfait(n):
s=0
for i in range(1,n,1):
if(n%2==0):
s=s+i
if(s==n):
ok=True
else:
ok=False
return ok
pgr1.py
app = QApplication([])
window = loadUi("forme2.ui")
def parfait(n):
s=0
for i in range(1,n+1):
if(n%2==0):
s=s+i
if(s==n):
ok=True
else:
ok=False
return ok
def verif(n):
n=int(n)
if (n<=0):
msg='verifier le nombre donné'
else:
test=parfait(n)
if(test==False):
msg=str(n)+' est un nombre parfait'
else:
msg=str(n)+' n est pas un nombre parfait'
1
Lycee Midoun 2021-2022
return msg
def play():
nb = window.tx.text()
res = verif(nb)
window.lb3.setText(res)
window.ok.clicked.connect(play)
window.show()
app.exec₍)
forme2.ui
2
Lycee Midoun 2021-2022
<width>181</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string><html><head/><body><p
align="center"><span style=" font-
size:16pt;">Nombre
parfait</span></p></body></html></string>
</property>
</widget>
<widget class="QLabel" name="lb2">
<property name="geometry">
<rect>
<x>30</x>
<y>80</y>
<width>161</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string><html><head/><body><p><span style=" font-
size:12pt;">Saisir votre
nombre</span></p></body></html></string>
</property>
</widget>
<widget class="QLabel" name="lb3">
<property name="geometry">
<rect>
<x>130</x>
<y>160</y>
<width>211</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string><html><head/><body><p
align="center">--</p></body></html></string>
</property>
</widget>
<widget class="QPushButton" name="ok">
<property name="geometry">
<rect>
<x>180</x>
<y>220</y>
<width>90</width>
<height>28</height>
</rect>
</property>
<property name="text">
3
Lycee Midoun 2021-2022
<string>Valider</string>
</property>
</widget>
<widget class="QLineEdit" name="tx">
<property name="geometry">
<rect>
<x>230</x>
<y>70</y>
<width>181</width>
<height>28</height>
</rect>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>500</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>