Good night. Does anyone would help me to add 3 more buttons (memory: MS, M+ and M-) commands to this calculator? I would appreciate so much! I have tried for hours and got nothing
It is very important to me. Thank you!!!
#### Buttons I donât know how to make it work
Button(width=4, text=âMsâ, relief=âflatâ, command=self.memo_add).place(x=360, y=50)
Button(width=4, text=âM+â, relief=âflatâ, command=self.memo_sum).place(x=360, y=90)
Button(width=4, text=âM-â, relief=âflatâ, command=self.memo_sub).place(x=360, y=130)
#### COMMANDS I NEED HELP WITH
def memo_add(self): # must save number to memory
def memo_sum(self): # must sum the saved number to the screen value
def memo_sub(self): # must subtract from the screen value
from tkinter import Tk, Entry, Button, StringVar
class Calculadora:
def __init__(self, base_calculadora):
base_calculadora.title('Calculadora')
base_calculadora.geometry('403x260+0+0')
self.memory = 0
base_calculadora.config(bg='#438')
base_calculadora.resizable()
self.equation = StringVar()
self.entry_value = ''
Entry(width=36, bg='lightblue', font=('Verdana', 16), textvariable=self.equation).place(x=0, y=0)
Button(width=8, text='(', relief='flat', command=lambda: self.show('(')).place(x=0, y=50)
Button(width=8, text=')', relief='flat', command=lambda: self.show(')')).place(x=90, y=50)
Button(width=8, text='%', relief='flat', command=lambda: self.show('%')).place(x=180, y=50)
Button(width=8, text='1', relief='flat', command=lambda: self.show(1)).place(x=0, y=90)
Button(width=8, text='2', relief='flat', command=lambda: self.show(2)).place(x=90, y=90)
Button(width=8, text='3', relief='flat', command=lambda: self.show(3)).place(x=180, y=90)
Button(width=8, text='4', relief='flat', command=lambda: self.show(4)).place(x=0, y=130)
Button(width=8, text='5', relief='flat', command=lambda: self.show(5)).place(x=90, y=130)
Button(width=8, text='6', relief='flat', command=lambda: self.show(6)).place(x=180, y=130)
Button(width=8, text='7', relief='flat', command=lambda: self.show(7)).place(x=0, y=170)
Button(width=8, text='8', relief='flat', command=lambda: self.show(8)).place(x=180, y=170)
Button(width=8, text='9', relief='flat', command=lambda: self.show(9)).place(x=90, y=170)
Button(width=8, text='0', relief='flat', command=lambda: self.show(0)).place(x=0, y=210)
Button(width=8, text='.', relief='flat', command=lambda: self.show('.')).place(x=90, y=210)
Button(width=8, text='+', relief='flat', command=lambda: self.show('+')).place(x=270, y=90)
Button(width=8, text='-', relief='flat', command=lambda: self.show('-')).place(x=270, y=130)
Button(width=8, text='/', relief='flat', command=lambda: self.show('/')).place(x=270, y=170)
Button(width=8, text='x', relief='flat', command=lambda: self.show('*')).place(x=270, y=210)
Button(width=8, text='=', bg='green', relief='flat', command=self.solve).place(x=180, y=210)
Button(width=8, text='AC', relief='flat', command=self.clear).place(x=270, y=50)
########### Buttons I don't know how to make it work
Button(width=4, text='Ms', relief='flat', command=self.memo_add).place(x=360, y=50) # must save to memory
Button(width=4, text='M+', relief='flat', command=self.memo_sum).place(x=360, y=90) # must sum to the screen value
Button(width=4, text='M-', relief='flat', command=self.memo_sub).place(x=360, y=130) # must subtract from the screen value
#### COMMANDS
def memo_add(self):
def memo_sum(self):
def memo_sub(self):
def show(self, value):
self.entry_value += str(value)
self.equation.set(self.entry_value)
def clear(self):
self.entry_value = ''
self.equation.set(self.entry_value)
def solve(self):
result = eval(self.entry_value)
self.equation.set(result)
root = Tk()
calculator = Calculadora(root)
root.mainloop()