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("Average Speed 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("Hours
and
Minutes",
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
.hours
=
QSpinBox(
self
)
self
.hours.setGeometry(
200
,
100
,
90
,
40
)
self
.hours.setFont(QFont(
'Times'
,
9
))
self
.hours.setAlignment(Qt.AlignCenter)
self
.minutes
=
QSpinBox(
self
)
self
.minutes.setGeometry(
290
,
100
,
90
,
40
)
self
.minutes.setMaximum(
60
)
self
.minutes.setFont(QFont(
'Times'
,
9
))
self
.minutes.setAlignment(Qt.AlignCenter)
d_label
=
QLabel("Distance (Km)",
self
)
d_label.setAlignment(Qt.AlignCenter)
d_label.setGeometry(
20
,
150
,
170
,
40
)
d_label.setStyleSheet("QLabel"
"{"
"border :
2px
solid black;"
"background : rgba(
70
,
70
,
70
,
35
);"
"}")
d_label.setFont(QFont(
'Times'
,
9
))
self
.distance
=
QSpinBox(
self
)
self
.distance.setGeometry(
200
,
150
,
180
,
40
)
self
.distance.setMaximum(
99999999
)
self
.distance.setFont(QFont(
'Times'
,
9
))
self
.distance.setAlignment(Qt.AlignCenter)
calculate
=
QPushButton("Calculate Speed",
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
):
hours
=
self
.hours.value()
minutes
=
self
.minutes.value()
distance
=
self
.distance.value()
if
distance
=
=
0
:
return
elif
hours
=
=
0
and
minutes
=
=
0
:
return
time
=
hours
+
minutes
/
60
speed
=
distance
/
time
speed
=
'%.2f'
%
speed
self
.result.setText(
str
(speed)
+
" Km
/
Hr")
App
=
QApplication(sys.argv)
window
=
Window()
sys.exit(App.
exec
())