├── ifelse.py └── kalkulyator.py /ifelse.py: -------------------------------------------------------------------------------- 1 | def ifsible(txt): 2 | lis = ['-', '+', '/', '*'] 3 | if not (txt[len(txt)-1] in lis): 4 | return True 5 | else: 6 | return False 7 | 8 | def ifsible_with_number(txt): 9 | if len(txt) > 0: 10 | if not (txt[len(txt)-1] == ')'): 11 | return True 12 | else: 13 | return False 14 | else: 15 | return True 16 | 17 | def ifsible_with_number1(txt): 18 | if len(txt) > 0: 19 | lis = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '-', '*', '/'] 20 | if txt[len(txt)-1] in lis and txt != None: 21 | return True 22 | else: 23 | return False 24 | else: 25 | return False 26 | 27 | def ifbracket(txt): 28 | if txt != '': 29 | return True 30 | else: 31 | return False 32 | 33 | def ifbrackets(txt): 34 | bracket1 = 0 35 | bracket2 = 0 36 | for i in txt: 37 | if i == '(': 38 | bracket1 += 1 39 | elif i == ')': 40 | bracket2 += 1 41 | 42 | if bracket1 == bracket2: 43 | return True 44 | else: 45 | return False 46 | 47 | def ifbrackets2(txt): 48 | bracket1 = 0 49 | bracket2 = 0 50 | for i in txt: 51 | if i == '(': 52 | bracket1 += 1 53 | elif i == ')': 54 | bracket2 += 1 55 | 56 | if bracket1-bracket2 > 0: 57 | return True 58 | else: 59 | return False 60 | 61 | def ifbrakets_with_number2(txt): 62 | lis = ['-', '+', '/', '*', '('] 63 | if(len(txt)>0): 64 | if not (txt[len(txt)-1] in lis): 65 | return True 66 | else: 67 | return False 68 | else: 69 | return True 70 | 71 | def ifbrakets_with_number(txt): 72 | lis = ['-', '+', '/', '*', '('] 73 | if(len(txt)>0): 74 | if txt[len(txt)-1] in lis: 75 | return True 76 | else: 77 | return False 78 | else: 79 | return True 80 | -------------------------------------------------------------------------------- /kalkulyator.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from ifelse import * 3 | from PyQt5.QtWidgets import ( 4 | QApplication, 5 | QWidget, 6 | QPushButton, 7 | QLineEdit, 8 | QLabel, 9 | QVBoxLayout, 10 | QHBoxLayout 11 | ) 12 | 13 | class Calculyator(QWidget): 14 | def __init__(self) -> None: 15 | super().__init__() 16 | self.txt = '' 17 | self.label = QLabel(self) 18 | 19 | 20 | self.v_boxmenu = QVBoxLayout() 21 | self.v_box = QVBoxLayout() 22 | self.v_box1 = QVBoxLayout() 23 | self.v_box2 = QVBoxLayout() 24 | self.v_box3 = QVBoxLayout() 25 | 26 | self.h_box = QHBoxLayout() 27 | self.h_box1 = QHBoxLayout() 28 | self.h_box2 = QHBoxLayout() 29 | self.h_box3 = QHBoxLayout() 30 | self.h_box4 = QHBoxLayout() 31 | 32 | self.bush_mines = QPushButton('-') 33 | self.bush_plus = QPushButton('+') 34 | self.bush_mult = QPushButton("*") 35 | self.bush_division = QPushButton('/') 36 | self.bush_equals = QPushButton('=') 37 | self.bush_1 = QPushButton('(') 38 | self.bush_2 = QPushButton(')') 39 | self.bush_3 = QPushButton('🔚') 40 | 41 | self.bush = QPushButton('0') 42 | self.bush1 = QPushButton('1') 43 | self.bush2 = QPushButton('2') 44 | self.bush3 = QPushButton('3') 45 | self.bush4 = QPushButton('4') 46 | self.bush5 = QPushButton('5') 47 | self.bush6 = QPushButton('6') 48 | self.bush7 = QPushButton('7') 49 | self.bush8 = QPushButton('8') 50 | self.bush9 = QPushButton('9') 51 | 52 | self.h_box.addWidget(self.bush1) 53 | self.h_box.addWidget(self.bush2) 54 | self.h_box.addWidget(self.bush3) 55 | self.h_box.addWidget(self.bush_3) 56 | 57 | self.h_box1.addWidget(self.bush4) 58 | self.h_box1.addWidget(self.bush5) 59 | self.h_box1.addWidget(self.bush6) 60 | self.h_box1.addWidget(self.bush_mult) 61 | 62 | self.h_box2.addWidget(self.bush7) 63 | self.h_box2.addWidget(self.bush8) 64 | self.h_box2.addWidget(self.bush9) 65 | self.h_box2.addWidget(self.bush_mines) 66 | 67 | self.h_box3.addWidget(self.bush) 68 | self.h_box3.addWidget(self.bush_equals) 69 | self.h_box3.addWidget(self.bush_plus) 70 | 71 | self.h_box4.addWidget(self.bush_1) 72 | self.h_box4.addWidget(self.bush_2) 73 | self.h_box4.addWidget(self.bush_division) 74 | 75 | self.v_box.addWidget(self.label) 76 | self.v_box.addLayout(self.h_box) 77 | self.v_box.addLayout(self.h_box1) 78 | self.v_box.addLayout(self.h_box2) 79 | self.v_box.addLayout(self.h_box3) 80 | self.v_box.addLayout(self.h_box4) 81 | 82 | self.setLayout(self.v_box) 83 | self.setFixedSize(600, 500) 84 | 85 | self.bush.clicked.connect(self.btn_bush) 86 | self.bush1.clicked.connect(self.btn_bush1) 87 | self.bush2.clicked.connect(self.btn_bush2) 88 | self.bush3.clicked.connect(self.btn_bush3) 89 | self.bush4.clicked.connect(self.btn_bush4) 90 | self.bush5.clicked.connect(self.btn_bush5) 91 | self.bush6.clicked.connect(self.btn_bush6) 92 | self.bush7.clicked.connect(self.btn_bush7) 93 | self.bush8.clicked.connect(self.btn_bush8) 94 | self.bush9.clicked.connect(self.btn_bush9) 95 | 96 | self.bush_mult.clicked.connect(self.btn_mult) 97 | self.bush_division.clicked.connect(self.btn_division) 98 | self.bush_plus.clicked.connect(self.btn_plus) 99 | self.bush_mines.clicked.connect(self.btn_mines) 100 | self.bush_equals.clicked.connect(self.btn_equals) 101 | self.bush_1.clicked.connect(self.btn_bush_1) 102 | self.bush_2.clicked.connect(self.btn_bush_2) 103 | self.bush_3.clicked.connect(self.btn_bush_3) 104 | 105 | 106 | def btn_bush(self): 107 | if ifsible_with_number1(self.txt): 108 | self.txt += '0' 109 | self.label.setText(self.txt) 110 | 111 | def btn_bush1(self): 112 | if ifsible_with_number(self.txt): 113 | self.txt += '1' 114 | self.label.setText(self.txt) 115 | 116 | def btn_bush2(self): 117 | if ifsible_with_number(self.txt): 118 | self.txt += '2' 119 | self.label.setText(self.txt) 120 | 121 | def btn_bush3(self): 122 | if ifsible_with_number(self.txt): 123 | self.txt += '3' 124 | self.label.setText(self.txt) 125 | 126 | def btn_bush4(self): 127 | if ifsible_with_number(self.txt): 128 | self.txt += '4' 129 | self.label.setText(self.txt) 130 | 131 | def btn_bush5(self): 132 | if ifsible_with_number(self.txt): 133 | self.txt += '5' 134 | self.label.setText(self.txt) 135 | 136 | def btn_bush6(self): 137 | if ifsible_with_number(self.txt): 138 | self.txt += '6' 139 | self.label.setText(self.txt) 140 | 141 | def btn_bush7(self): 142 | if ifsible_with_number(self.txt): 143 | self.txt += '7' 144 | self.label.setText(self.txt) 145 | 146 | def btn_bush8(self): 147 | if ifsible_with_number(self.txt): 148 | self.txt += '8' 149 | self.label.setText(self.txt) 150 | 151 | def btn_bush9(self): 152 | if ifsible_with_number(self.txt): 153 | self.txt += '9' 154 | self.label.setText(self.txt) 155 | 156 | def btn_mult(self): 157 | if ifbracket(self.txt) and ifsible(self.txt): 158 | self.txt += '*' 159 | self.label.setText(self.txt) 160 | 161 | def btn_division(self): 162 | if ifbracket(self.txt) and ifsible(self.txt): 163 | self.txt += '/' 164 | self.label.setText(self.txt) 165 | 166 | def btn_plus(self): 167 | if ifbracket(self.txt) and ifsible(self.txt): 168 | self.txt += '+' 169 | self.label.setText(self.txt) 170 | 171 | def btn_mines(self): 172 | if ifbracket(self.txt) and ifsible(self.txt): 173 | self.txt += '-' 174 | self.label.setText(self.txt) 175 | 176 | def btn_equals(self): 177 | if ifbrackets(self.txt): 178 | if ifbracket(self.txt) and ifsible(self.txt): 179 | self.label.clear() 180 | self.txt = str(eval(self.txt)) 181 | self.label.setText(self.txt) 182 | 183 | def btn_bush_1(self): 184 | if ifbrakets_with_number(self.txt): 185 | self.txt += '(' 186 | self.label.setText(self.txt) 187 | 188 | def btn_bush_2(self): 189 | if ifbrakets_with_number2(self.txt) and ifbrackets2(self.txt) and ifbracket(self.txt): 190 | self.txt += ')' 191 | self.label.setText(self.txt) 192 | 193 | def btn_bush_3(self): 194 | self.txt = self.txt[:-1] 195 | self.label.setText(self.txt) 196 | 197 | 198 | app = QApplication(sys.argv) 199 | win = Calculyator() 200 | win.show() 201 | app.exec_() 202 | 203 | 204 | --------------------------------------------------------------------------------