Advertisement
Guest User

Памагити

a guest
Jul 17th, 2021
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.61 KB | None | 0 0
  1. from PyQt5 import QtWidgets, uic
  2. from PyQt5.QtWidgets import QWidget, QMessageBox, QApplication
  3. import sys
  4.  
  5.  
  6. app = QtWidgets.QApplication([])
  7. win = uic.loadUi("label.ui")  # расположение файла .ui
  8. summ_con = 0
  9. i = 0
  10. set_1 = ""
  11. def click():
  12.     try:
  13.         global i
  14.         global summ_con
  15.         int_from_str_array = []
  16.         #print(int_from_str_array)
  17.         line = win.lineEdit.text()
  18.         for word in line.split():
  19.             try:
  20.                 int_from_str_array.append(int(word))
  21.                 #print(int_from_str_array)
  22.             except ValueError:
  23.                 pass
  24.         for i in range(len(int_from_str_array)):
  25.             summ_con = summ_con + int_from_str_array[i]
  26.         #print(summ_con)
  27.         kol = 0
  28.         while i < len(win.lineEdit.text()):
  29.             if win.lineEdit.text()[i] == "+":
  30.                 kol = kol + 1
  31.             i += 1
  32.  
  33.  
  34.  
  35.         if kol == (len(int_from_str_array) - 1):
  36.  
  37.             #print(int_from_str_array)
  38.             win.listWidget.addItem(win.lineEdit.text() + " = " + str(summ_con))
  39.             win.label.setText("Результат сложения: " + str(summ_con))
  40.             summ_con = 0
  41.         else:
  42.             #print(int_from_str_array)
  43.             int_from_str_array.clear()
  44.             QMessageBox.about(win, "Ошибка", "Введите корректное число знаков действия!")
  45.  
  46.     except ValueError:
  47.         QMessageBox.about(win, "Ошибка", "Нужно ввести 2 целых числа!")
  48.  
  49. win.summ_bth.clicked.connect(click)
  50.  
  51.  
  52. win.show()
  53. sys.exit(app.exec())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement