0% found this document useful (0 votes)
10 views

Correction Tp2 Qt Designer Python 1

The document contains Python code for a program that checks if a number is perfect using PyQt5 for the GUI. It includes two scripts: one for the logic of determining perfect numbers and another for the GUI interface. The interface allows users to input a number and receive feedback on whether it is a perfect number or not.

Uploaded by

mohamedkhili515
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Correction Tp2 Qt Designer Python 1

The document contains Python code for a program that checks if a number is perfect using PyQt5 for the GUI. It includes two scripts: one for the logic of determining perfect numbers and another for the GUI interface. The interface allows users to input a number and receive feedback on whether it is a perfect number or not.

Uploaded by

mohamedkhili515
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Lycee Midoun 2021-2022

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

from PyQt5.QtWidgets import QApplication


from PyQt5.uic import loadUi

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

<?xml version="1.0" encoding="UTF-8"?>


<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>500</width>
<height>400</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>500</width>
<height>400</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>500</width>
<height>400</height>
</size>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QLabel" name="lb1">
<property name="geometry">
<rect>
<x>130</x>
<y>20</y>

2
Lycee Midoun 2021-2022

<width>181</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p
align=&quot;center&quot;&gt;&lt;span style=&quot; font-
size:16pt;&quot;&gt;Nombre
parfait&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</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>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-
size:12pt;&quot;&gt;Saisir votre
nombre&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</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>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p
align=&quot;center&quot;&gt;--&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</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>

You might also like