Я не проверял ваши формулы расчетов. Я прокомментировал код, который предложу вам изучить. Если что-то не понятно - спросите.
main.py
import sys
from PyQt5 import QtWidgets
from deposits import Ui_MainWindow
class ExampleApp(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
# какие-то начальные установки, если они нужны ?
self.lineEdit.setText(f'{1000.1012345:.2f}')
self.lineEdit_2.setText(f'{5.5:.2f}')
self.lineEdit_3.setText(f'{12}')
# vvvvvvv
self.pushButton.clicked.connect(self.get_result)
# зачем вам кнопка ниже ??? для чего она ???
self.pushButton_2.clicked.connect(self.get_result)
self.lineEdit_4.setReadOnly(True)
self.lineEdit.setFocus()
def get_result(self):
if not self.lineEdit.text() or \
not self.lineEdit_2.text() or \
not self.lineEdit_3.text():
msg = QtWidgets.QMessageBox.information(
self,
'Внимание',
'Заполните пожалуйста все поля для расчета.')
self.lineEdit.setFocus()
return
# вытаскиваем исходные данные и преобразовываем их в нужный для расчета тип
summ = float(self.lineEdit.text())
percent = float(self.lineEdit_2.text())
period = int(self.lineEdit_3.text())
#print(f'checkBox = {self.checkBox.isChecked()}')
if not self.checkBox.isChecked():
summ = summ + round(summ * (percent / 100), 2)
else:
for _ in range(period):
summ += round(summ * (percent / 100), 2) / period
self.lineEdit_4.setText(f'{summ:.2f}')
def main():
app = QtWidgets.QApplication(sys.argv)
window = ExampleApp()
window.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
deposits.py
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(168, 360)
MainWindow.setMinimumSize(QtCore.QSize(168, 360))
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.checkBox = QtWidgets.QCheckBox(self.centralwidget)
self.checkBox.setGeometry(QtCore.QRect(20, 160, 121, 17))
self.checkBox.setObjectName("checkBox")
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(20, 30, 121, 21))
self.lineEdit.setObjectName("lineEdit")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(20, 10, 121, 16))
self.label.setObjectName("label")
self.lineEdit_2 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_2.setGeometry(QtCore.QRect(20, 80, 121, 21))
self.lineEdit_2.setObjectName("lineEdit_2")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(20, 60, 121, 16))
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(20, 110, 121, 16))
self.label_3.setObjectName("label_3")
self.lineEdit_3 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_3.setGeometry(QtCore.QRect(20, 130, 121, 21))
self.lineEdit_3.setObjectName("lineEdit_3")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(20, 190, 121, 21))
self.pushButton.setObjectName("pushButton")
self.label_4 = QtWidgets.QLabel(self.centralwidget)
self.label_4.setGeometry(QtCore.QRect(20, 240, 121, 16))
self.label_4.setObjectName("label_4")
self.lineEdit_4 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_4.setGeometry(QtCore.QRect(20, 260, 121, 21))
self.lineEdit_4.setObjectName("lineEdit_4")
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(20, 300, 121, 21))
self.pushButton_2.setObjectName("pushButton_2")
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.checkBox.setText(_translate("MainWindow", "Капитализация?"))
self.label.setText(_translate("MainWindow", "<html><head/><body><p>Сумма вклада</p></body></html>"))
self.label_2.setText(_translate("MainWindow", "Процент вклада"))
self.label_3.setText(_translate("MainWindow", "Срок вклада в месяцах"))
self.pushButton.setText(_translate("MainWindow", "Рассчитать"))
self.label_4.setText(_translate("MainWindow", "<html><head/><body><p>Вы получите</p></body></html>"))
self.pushButton_2.setText(_translate("MainWindow", "Рассчитать снова"))
deposits.py
.