from
PyQt5.QtWidgets
import
*
from
PyQt5
import
QtCore, QtGui
from
PyQt5.QtGui
import
*
from
PyQt5.QtCore
import
*
import
datetime
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(
"Dog Age Calculator"
,
self
)
head.setWordWrap(
True
)
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)
age_label
=
QLabel(
"Age of Dog "
,
self
)
age_label.setGeometry(
50
,
120
,
147
,
40
)
age_label.setAlignment(Qt.AlignCenter)
age_label.setStyleSheet(
"QLabel"
"{"
"border : 2px solid black;"
"background : rgba(70, 70, 70, 35);"
"}"
)
age_label.setFont(QFont(
'Times'
,
9
))
self
.age
=
QSpinBox(
self
)
self
.age.setGeometry(
203
,
120
,
147
,
40
)
self
.age.setMaximum(
20
)
self
.age.setMinimum(
1
)
self
.age.setSuffix(
" year(s)"
)
self
.age.setFont(QFont(
'Times'
,
9
))
self
.age.setAlignment(Qt.AlignCenter)
calculate
=
QPushButton(
"Calculate Age"
,
self
)
calculate.setGeometry(
100
,
200
,
200
,
40
)
calculate.clicked.connect(
self
.calculate)
color
=
QGraphicsColorizeEffect()
color.setColor(Qt.blue)
calculate.setGraphicsEffect(color)
self
.result
=
QLabel(
self
)
self
.result.setAlignment(Qt.AlignCenter)
self
.result.setGeometry(
50
,
280
,
300
,
70
)
self
.result.setWordWrap(
True
)
self
.result.setStyleSheet(
"QLabel"
"{"
"border : 3px solid black;"
"background : white;"
"}"
)
self
.result.setFont(QFont(
'Arial'
,
11
))
def
calculate(
self
):
value
=
self
.age.value()
if
value
=
=
1
:
d_age
=
15
elif
value
=
=
2
:
d_age
=
24
else
:
d_age
=
24
+
(value
-
2
)
*
4
self
.result.setText(
"If your dog were a human, it would be : "
+
str
(d_age)
+
" years old !"
)
App
=
QApplication(sys.argv)
window
=
Window()
sys.exit(App.
exec
())