From 2ba817f55868807c677c0863b31d2b4fc3b41e0b Mon Sep 17 00:00:00 2001 From: giannisster Date: Wed, 31 Dec 2025 14:33:20 +0200 Subject: [PATCH] Added CLR button which clears the calculator's input in pythontestcalc.py --- pythontestcalc.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pythontestcalc.py b/pythontestcalc.py index a1f0941..554028f 100644 --- a/pythontestcalc.py +++ b/pythontestcalc.py @@ -15,7 +15,7 @@ def __init__(self, root): '7', '8', '9', '/', '4', '5', '6', '*', '1', '2', '3', '-', - '0', '.', '=', '+' + '0', '.', '=', '+', ] # Create buttons @@ -27,6 +27,9 @@ def __init__(self, root): else: tk.Button(root, text=button, command=lambda b=button: self.entry.insert(tk.END, b)).grid(row=row, column=col, padx=5, pady=5, sticky='nsew') + # CLR button + tk.Button(root, text='CLR', command=self.clear).grid(row=5, column=0, padx=5, pady=5, sticky='nsew') + def calculate(self): try: result = eval(self.entry.get()) @@ -36,6 +39,9 @@ def calculate(self): self.entry.delete(0, tk.END) self.entry.insert(tk.END, "Error") + def clear(self): + self.entry.delete(0, tk.END) + def run_calculator(): root = tk.Tk() my_calculator = Calculator(root)