Calculadora: configurando o botão de igual e o número da direita

This commit is contained in:
Luiz Otávio
2023-03-03 07:36:16 -03:00
parent 98c050e160
commit b379fae718

View File

@@ -83,6 +83,9 @@ class ButtonsGrid(QGridLayout):
self._makeSlot(self._operatorClicked, button)
)
if text in '=':
self._connectButtonClicked(button, self._eq)
def _makeSlot(self, func, *args, **kwargs):
@ Slot(bool)
def realSlot(_):
@@ -123,3 +126,24 @@ class ButtonsGrid(QGridLayout):
self._op = buttonText
self.equation = f'{self._left} {self._op} ??'
def _eq(self):
displayText = self.display.text()
if not isValidNumber(displayText):
print('Sem nada para a direita')
return
self._right = float(displayText)
self.equation = f'{self._left} {self._op} {self._right}'
result = 0.0
try:
result = eval(self.equation)
except ZeroDivisionError:
print('Zero Division Error')
self.display.clear()
self.info.setText(f'{self.equation} = {result}')
self._left = result
self._right = None