Calculadora: configurando o botão de igual e o número da direita
This commit is contained in:
@@ -83,6 +83,9 @@ class ButtonsGrid(QGridLayout):
|
|||||||
self._makeSlot(self._operatorClicked, button)
|
self._makeSlot(self._operatorClicked, button)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if text in '=':
|
||||||
|
self._connectButtonClicked(button, self._eq)
|
||||||
|
|
||||||
def _makeSlot(self, func, *args, **kwargs):
|
def _makeSlot(self, func, *args, **kwargs):
|
||||||
@ Slot(bool)
|
@ Slot(bool)
|
||||||
def realSlot(_):
|
def realSlot(_):
|
||||||
@@ -123,3 +126,24 @@ class ButtonsGrid(QGridLayout):
|
|||||||
|
|
||||||
self._op = buttonText
|
self._op = buttonText
|
||||||
self.equation = f'{self._left} {self._op} ??'
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user