from
PyQt5.QtWidgets
import
*
from
PyQt5
import
QtCore, QtGui
from
PyQt5.QtGui
import
*
from
PyQt5.QtCore
import
*
import
sys
class
Window(QMainWindow):
def
__init__(
self
):
super
().__init__()
self
.setWindowTitle(
"Python "
)
self
.w_width
=
400
self
.w_height
=
400
self
.setGeometry(
100
,
100
,
self
.w_width,
self
.w_height)
self
.UiComponents()
self
.show()
def
UiComponents(
self
):
head
=
QLabel(
"Percentile Calculator"
,
self
)
head.setGeometry(
0
,
10
,
400
,
60
)
font
=
QFont(
'Times'
,
15
)
font.setBold(
True
)
font.setItalic(
True
)
font.setUnderline(
True
)
head.setFont(font)
head.setAlignment(Qt.AlignCenter)
color
=
QGraphicsColorizeEffect(
self
)
color.setColor(Qt.darkCyan)
head.setGraphicsEffect(color)
t_label
=
QLabel(
"Total Participants"
,
self
)
t_label.setAlignment(Qt.AlignCenter)
t_label.setGeometry(
20
,
100
,
170
,
40
)
t_label.setStyleSheet(
"QLabel"
"{"
"border : 2px solid black;"
"background : rgba(70, 70, 70, 35);"
"}"
)
t_label.setFont(QFont(
'Times'
,
9
))
self
.total
=
QLineEdit(
self
)
onlyInt
=
QIntValidator()
self
.total.setValidator(onlyInt)
self
.total.setGeometry(
200
,
100
,
180
,
40
)
self
.total.setAlignment(Qt.AlignCenter)
self
.total.setFont(QFont(
'Times'
,
9
))
r_label
=
QLabel(
"Rank "
,
self
)
r_label.setAlignment(Qt.AlignCenter)
r_label.setGeometry(
20
,
150
,
170
,
40
)
r_label.setStyleSheet(
"QLabel"
"{"
"border : 2px solid black;"
"background : rgba(70, 70, 70, 35);"
"}"
)
r_label.setFont(QFont(
'Times'
,
9
))
self
.rank
=
QLineEdit(
self
)
onlyInt
=
QIntValidator()
self
.rank.setValidator(onlyInt)
self
.rank.setGeometry(
200
,
150
,
180
,
40
)
self
.rank.setAlignment(Qt.AlignCenter)
self
.rank.setFont(QFont(
'Times'
,
9
))
calculate
=
QPushButton(
"Calculate Percentile"
,
self
)
calculate.setGeometry(
125
,
220
,
150
,
40
)
calculate.clicked.connect(
self
.calculate_action)
self
.result
=
QLabel(
self
)
self
.result.setAlignment(Qt.AlignCenter)
self
.result.setGeometry(
50
,
300
,
300
,
60
)
self
.result.setStyleSheet(
"QLabel"
"{"
"border : 3px solid black;"
"background : white;"
"}"
)
self
.result.setFont(QFont(
'Arial'
,
11
))
def
calculate_action(
self
):
students
=
self
.total.text()
rank
=
self
.rank.text()
if
len
(students)
=
=
0
or
len
(rank)
=
=
0
:
return
students
=
int
(students)
rank
=
int
(rank)
if
students
=
=
0
or
rank
=
=
0
:
return
result
=
round
((students
-
rank)
/
students
*
100
,
3
)
self
.result.setText(
"Percentile : "
+
str
(result))
App
=
QApplication(sys.argv)
window
=
Window()
sys.exit(App.
exec
())