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
=
550
self
.w_height
=
300
self
.setGeometry(
100
,
100
,
self
.w_width,
self
.w_height)
self
.UiComponents()
self
.show()
def
UiComponents(
self
):
head
=
QLabel("Ratio Calculator",
self
)
head.setWordWrap(
True
)
head.setGeometry(
0
,
10
,
550
,
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)
self
.a_spin
=
QSpinBox(
self
)
self
.a_spin.setGeometry(
50
,
90
,
90
,
35
)
self
.a_spin.setAlignment(Qt.AlignCenter)
self
.a_spin.setRange(
1
,
999999
)
l1
=
QLabel(" : ",
self
)
l1.setGeometry(
140
,
90
,
30
,
35
)
l1.setAlignment(Qt.AlignCenter)
self
.b_spin
=
QSpinBox(
self
)
self
.b_spin.setGeometry(
170
,
90
,
90
,
35
)
self
.b_spin.setAlignment(Qt.AlignCenter)
self
.b_spin.setRange(
1
,
999999
)
l2
=
QLabel("
=
",
self
)
l2.setGeometry(
260
,
90
,
30
,
35
)
l2.setAlignment(Qt.AlignCenter)
self
.c_spin
=
QSpinBox(
self
)
self
.c_spin.setGeometry(
290
,
90
,
90
,
35
)
self
.c_spin.setAlignment(Qt.AlignCenter)
self
.c_spin.setRange(
1
,
999999
)
l3
=
QLabel(" : ",
self
)
l3.setGeometry(
380
,
90
,
20
,
35
)
l3.setAlignment(Qt.AlignCenter)
lx
=
QLabel("X",
self
)
lx.setGeometry(
410
,
90
,
90
,
35
)
lx.setAlignment(Qt.AlignCenter)
lx.setStyleSheet("QLabel"
"{"
"border :
1px
solid black;"
"background
-
color : white;"
"font
-
size :
15px
;"
"}")
calculate
=
QPushButton("Calculate",
self
)
calculate.setGeometry(
175
,
150
,
200
,
40
)
calculate.clicked.connect(
self
.calculate)
color
=
QGraphicsColorizeEffect()
color.setColor(Qt.darkGreen)
calculate.setGraphicsEffect(color)
self
.result
=
QLabel(
self
)
self
.result.setAlignment(Qt.AlignCenter)
self
.result.setGeometry(
125
,
210
,
300
,
60
)
self
.result.setWordWrap(
True
)
self
.result.setStyleSheet("QLabel"
"{"
"border :
3px
solid black;"
"background : white;"
"}")
self
.result.setFont(QFont(
'Arial'
,
11
))
def
calculate(
self
):
a
=
self
.a_spin.value()
b
=
self
.b_spin.value()
c
=
self
.c_spin.value()
x
=
(c
*
b)
/
a
if
x
%
1
=
=
0
:
x
=
int
(x)
self
.result.setText(
str
(a)
+
" : "
+
str
(b)
+
"
=
"
+
str
(c)
+
" : "
+
str
(x))
App
=
QApplication(sys.argv)
window
=
Window()
sys.exit(App.
exec
())