Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions calculator/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ def __init__(self):
self.display = None
self.buttons = None

def key_handler(self, event):
if event.char.isdigit():
self.calculator.add_digit(event.char)
elif event.char in set(item.value for item in api.Operator):
self.calculator.set_operator(event.char)
elif event.char == "=" or event.keysym == "Return":
if self.calculator.current_part == "last":
self.calculator.solve()
elif event.char == ".":
self.calculator.add_decimal()
elif event.keysym == "BackSpace":
self.calculator.clear_entry()


def create_gui(self):
self.window.title("Calculator")

Expand All @@ -20,6 +34,8 @@ def create_gui(self):

self.display.frame.pack(fill=tk.BOTH,expand=True,side=tk.TOP,padx=10,pady=(10,0))
self.buttons.frame.pack(fill=tk.BOTH,expand=True,side=tk.BOTTOM,padx=10,pady=(0,10))

self.window.bind("<Key>", self.key_handler)

def update(self):
self.buttons.update()
Expand Down