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
=
430
self
.setGeometry(
100
,
100
,
self
.w_width,
self
.w_height)
self
.UiComponents()
self
.show()
def
UiComponents(
self
):
head
=
QLabel("Silver Ratio 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)
self
.length1
=
QRadioButton("First Length (A)",
self
)
self
.length1.setGeometry(
50
,
90
,
140
,
40
)
self
.length1.setFont(QFont(
'Times'
,
9
))
self
.l1
=
QSpinBox(
self
)
self
.l1.setMaximum(
999999
)
self
.l1.setGeometry(
200
,
90
,
160
,
40
)
self
.l1.setFont(QFont(
'Times'
,
9
))
self
.l1.setAlignment(Qt.AlignCenter)
self
.length2
=
QRadioButton("Second Length (B)",
self
)
self
.length2.setGeometry(
50
,
150
,
145
,
40
)
self
.length2.setFont(QFont(
'Times'
,
9
))
self
.l2
=
QSpinBox(
self
)
self
.l2.setMaximum(
999999
)
self
.l2.setGeometry(
200
,
150
,
160
,
40
)
self
.l2.setFont(QFont(
'Times'
,
9
))
self
.l2.setAlignment(Qt.AlignCenter)
self
.length1.clicked.connect(
self
.radio_method)
self
.length2.clicked.connect(
self
.radio_method)
self
.l1.valueChanged.connect(
self
.spin_method)
self
.l2.valueChanged.connect(
self
.spin_method)
self
.l1.setDisabled(
True
)
self
.l2.setDisabled(
True
)
calculate
=
QPushButton("Calculate",
self
)
calculate.setGeometry(
100
,
270
,
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
,
330
,
300
,
70
)
self
.result.setWordWrap(
True
)
self
.result.setStyleSheet("QLabel"
"{"
"border :
3px
solid black;"
"background : white;"
"}")
self
.result.setFont(QFont(
'Arial'
,
11
))
def
radio_method(
self
):
if
self
.length1.isChecked():
self
.l1.setEnabled(
True
)
self
.l2.setDisabled(
True
)
self
.check1
=
True
self
.check2
=
False
elif
self
.length2.isChecked():
self
.l2.setEnabled(
True
)
self
.l1.setDisabled(
True
)
self
.check1
=
False
self
.check2
=
True
def
spin_method(
self
):
if
self
.l1.isEnabled():
self
.l2.setValue(
0
)
elif
self
.l2.isEnabled():
self
.l1.setValue(
0
)
def
calculate(
self
):
silver
=
2.414
if
self
.check1
=
=
True
:
A
=
self
.l1.value()
B
=
A
/
silver
elif
self
.check2
=
=
True
:
B
=
self
.l2.value()
A
=
B
*
silver
A
=
"{:.
2f
}".
format
(A)
B
=
"{:.
2f
}".
format
(B)
self
.result.setText("A
=
"
+
str
(A)
+
", B
=
"
+
str
(B))
App
=
QApplication(sys.argv)
window
=
Window()
sys.exit(App.
exec
())