From b379fae71833e0b8da9305f8f31db2c30b2ebdea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Ot=C3=A1vio?= Date: Fri, 3 Mar 2023 07:36:16 -0300 Subject: [PATCH] =?UTF-8?q?Calculadora:=20configurando=20o=20bot=C3=A3o=20?= =?UTF-8?q?de=20igual=20e=20o=20n=C3=BAmero=20da=20direita?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aula202-calculadora/buttons.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/aula202-calculadora/buttons.py b/aula202-calculadora/buttons.py index fe73b05..447447d 100644 --- a/aula202-calculadora/buttons.py +++ b/aula202-calculadora/buttons.py @@ -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