Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PyQt5 import QtWidgets, uic
- from PyQt5.QtWidgets import QWidget, QMessageBox, QApplication
- import sys
- app = QtWidgets.QApplication([])
- win = uic.loadUi("label.ui") # расположение файла .ui
- summ_con = 0
- i = 0
- set_1 = ""
- def click():
- try:
- global i
- global summ_con
- int_from_str_array = []
- #print(int_from_str_array)
- line = win.lineEdit.text()
- for word in line.split():
- try:
- int_from_str_array.append(int(word))
- #print(int_from_str_array)
- except ValueError:
- pass
- for i in range(len(int_from_str_array)):
- summ_con = summ_con + int_from_str_array[i]
- #print(summ_con)
- kol = 0
- while i < len(win.lineEdit.text()):
- if win.lineEdit.text()[i] == "+":
- kol = kol + 1
- i += 1
- if kol == (len(int_from_str_array) - 1):
- #print(int_from_str_array)
- win.listWidget.addItem(win.lineEdit.text() + " = " + str(summ_con))
- win.label.setText("Результат сложения: " + str(summ_con))
- summ_con = 0
- else:
- #print(int_from_str_array)
- int_from_str_array.clear()
- QMessageBox.about(win, "Ошибка", "Введите корректное число знаков действия!")
- except ValueError:
- QMessageBox.about(win, "Ошибка", "Нужно ввести 2 целых числа!")
- win.summ_bth.clicked.connect(click)
- win.show()
- sys.exit(app.exec())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement