-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculator.py
89 lines (77 loc) · 3.24 KB
/
calculator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import pickle
from PyQt5 import uic
from PyQt5.QtCore import QDate
from PyQt5.QtWidgets import QApplication
Form, Window = uic.loadUiType("calculator.ui")
app = QApplication([])
window = Window()
form = Form()
form.setupUi(window)
window.show()
def click_plus():
try:
first_count = form.textEdit.toPlainText()
second_count = form.textEdit_2.toPlainText()
result = float(first_count) + float(second_count)
print(result)
form.label_5.setText("%s" %result)
except ValueError:
form.label_5.setText("Проверьте корректность введенных данных")
def click_minus():
try:
first_count = form.textEdit.toPlainText()
second_count = form.textEdit_2.toPlainText()
result = float(first_count) - float(second_count)
print(result)
form.label_5.setText("%s" %result)
except ValueError:
form.label_5.setText("Проверьте корректность введенных данных")
def click_multiply():
try:
first_count = form.textEdit.toPlainText()
second_count = form.textEdit_2.toPlainText()
result = float(first_count) * float(second_count)
print(result)
form.label_5.setText("%s" %result)
except ValueError:
form.label_5.setText("Проверьте корректность введенных данных")
def click_simple_division():
try:
first_count = form.textEdit.toPlainText()
second_count = form.textEdit_2.toPlainText()
result = float(first_count) / float(second_count)
print(result)
form.label_5.setText("%s" %result)
except ZeroDivisionError:
form.label_5.setText('На ноль делить нельзя')
except ValueError:
form.label_5.setText("Проверьте корректность введенных данных")
def click_whole_division():
try:
first_count = form.textEdit.toPlainText()
second_count = form.textEdit_2.toPlainText()
result = float(first_count) // float(second_count)
print(result)
form.label_5.setText("целая часть от деления: %s" %result)
except ZeroDivisionError:
form.label_5.setText('На ноль делить нельзя')
except ValueError:
form.label_5.setText("Проверьте корректность введенных данных")
def click_residual_division():
try:
first_count = form.textEdit.toPlainText()
second_count = form.textEdit_2.toPlainText()
result = float(first_count) % float(second_count)
print(result)
form.label_5.setText("остаток от деления: %s" %result)
except ZeroDivisionError:
form.label_5.setText('На ноль делить нельзя')
except ValueError:
form.label_5.setText("Проверьте корректность введенных данных")
form.pushButton.clicked.connect(click_plus)
form.pushButton_2.clicked.connect(click_minus)
form.pushButton_3.clicked.connect(click_multiply)
form.pushButton_4.clicked.connect(click_simple_division)
form.pushButton_5.clicked.connect(click_whole_division)
form.pushButton_6.clicked.connect(click_residual_division)
app.exec_()