The calculator display the numbers when the buttons clicked, it does the first operations, but there are some issues

pull/923/head
BPM17 1 month ago
parent 4984c5f68b
commit b3da3e04d1

@ -17,7 +17,10 @@ class Calculator():
# The best way to place the buttons is ussing grid
# It also require a main frame
# The frame is also the master for the buttons and the label
self.buttonsSimbols=["A/C", "+/-", "/", "<-", "7","8","9","x", "4","5","6","-", "1","2","3","+", "0", ".", "="]
self.buttonsSimbols=["A/C", "+/-", " / ", "<-", "7","8","9","x", "4","5","6","-", "1","2","3","+", "0", ".", "="]
self.buttons = []
self.word = ""
self.res = 0
self.CreateFrames()
self.screen = ttk.Label(self.screenFrame, text="HOLA MUNDO", font=("Arial", 20, "bold"),justify="right")
self.screen.pack(padx=10, pady=10, expand=True)
@ -39,15 +42,44 @@ class Calculator():
for j in range (6):
for i in range (4):
if l < len(self.buttonsSimbols):
self.buttons = ttk.Button(self.buttonsFrame, text= self.buttonsSimbols[l])
self.buttons.grid(column=i, row=j,sticky="nsew", padx=5, pady=5)
self.buttons.append( ttk.Button(self.buttonsFrame, text= self.buttonsSimbols[l]))
self.buttons[l].grid(column=i, row=j,sticky="nsew", padx=5, pady=5)
self.buttons[l].bind("<Button-1>", self.ClickedButton)
l +=1
def ClickedButton(self, event):
if event.widget['text'] == "=":
self.ProcessText(event)
else:
self.word = self.word + event.widget['text']
self.screen.config(text = self.word)
def ProcessText(self, event):
self.screen.config(text="")
if self.word.find('+'):
self.res = self.word.split('+')
self.Operation("+", event)
elif self.word.find('-'):
self.res = self.word.split('-')
self.Operation("-", event)
elif self.word.find('/'):
self.res = self.word.split('/')
self.Operation("/", event)
elif self.word.find('x'):
self.res = self.word.split('x')
self.Operation("*", event)
def Operation(self, simbol, event):
print(self.res)
self.word = str(eval(f"{int(self.res[0])} {simbol} {int(self.res[1])}"))
print(type(self.word))
self.screen.config(text = self.word)
def Configure(self):
for i in range(5):
self.mainFrame.rowconfigure(i, weight=1)
self.mainFrame.rowconfigure(i, weight=1, minsize=50)
for i in range(4):
self.mainFrame.columnconfigure(i, weight=1)
self.mainFrame.columnconfigure(i, weight=1, minsize=50)
def __str__(self):
return super().__str__()

Loading…
Cancel
Save