diff --git a/Calculator/Components/Calculator_Button.py b/Calculator/Components/Calculator_Button.py index 6b029f4..7e93ee0 100644 --- a/Calculator/Components/Calculator_Button.py +++ b/Calculator/Components/Calculator_Button.py @@ -1,14 +1,77 @@ +# from tkinter import * + +# class CalculatorButtons: +# def __init__(self, root, entry): +# self.root = root +# self.entry = entry +# self.value1 = 0 +# self.value2 = 0 +# self.operator = '' + +# def on_button_click(self,textbtn): +# match textbtn: +# case '+': +# self.value1 = float(self.entry.get()) +# self.operator = '+' +# self.entry.delete(0, END) +# case '-': +# self.value1 = float(self.entry.get()) +# self.operator = '-' +# self.entry.delete(0, END) +# case '*': +# self.value1 = float(self.entry.get()) +# self.operator = '*' +# self.entry.delete(0, END) +# case '/': +# self.value1 = float(self.entry.get()) +# self.operator = '/' +# self.entry.delete(0, END) +# case '=': +# result = 0 +# self.value2 = float(self.entry.get()) +# self.entry.delete(0, END) +# try: +# if self.operator == '+': +# result = self.value1 + self.value2 +# elif self.operator == '-': +# result = self.value1 - self.value2 +# elif self.operator == '*': +# result = self.value1 * self.value2 +# elif self.operator == '/': +# result = self.value1 / self.value2 +# self.entry.insert(0, str(result)) +# except ZeroDivisionError: +# self.entry.insert(0, "Error") +# except SyntaxError: +# self.entry.insert(0, "Error") +# case 'CL': +# self.entry.delete(0, END) +# CalculatorButtons.value1 = 0 +# CalculatorButtons.value2 = 0 +# CalculatorButtons.operator = '' +# case _: +# self.entry.insert(END, textbtn) + +# def main(self,textbtn, x , y): +# btn = Button(self.root, text=textbtn, font=("Arial", 18), width=5, height=2, +# bg="#34495E", fg="white", relief=RAISED, bd=5,command=lambda :self.on_button_click(textbtn)) +# btn.grid(row=x, column=y, sticky="nsew") + + from tkinter import * -class CalculatorButtons: +class CalculatorButtons: def __init__(self, root, entry): self.root = root self.entry = entry self.value1 = 0 self.value2 = 0 self.operator = '' - - def on_button_click(self,textbtn): + + self.button_frame = Frame(self.root) + self.button_frame.grid(row=1, column=0, columnspan=4, pady=20, padx=20) + + def on_button_click(self, textbtn): match textbtn: case '+': self.value1 = float(self.entry.get()) @@ -32,7 +95,7 @@ def on_button_click(self,textbtn): self.entry.delete(0, END) try: if self.operator == '+': - result = self.value1 + self.value2 + result = self.value1 + self.value2 elif self.operator == '-': result = self.value1 - self.value2 elif self.operator == '*': @@ -51,8 +114,15 @@ def on_button_click(self,textbtn): CalculatorButtons.operator = '' case _: self.entry.insert(END, textbtn) - - def main(self,textbtn, x , y): - btn = Button(self.root, text=textbtn, font=("Arial", 18), width=5, height=2, - bg="#34495E", fg="white", relief=RAISED, bd=5,command=lambda :self.on_button_click(textbtn)) - btn.grid(row=x, column=y, sticky="nsew") \ No newline at end of file + + def create_canvas_button(self, textbtn, x, y, bg_color): + button_canvas = Canvas(self.button_frame, width=110, height=55, bg=bg_color, bd=0, highlightthickness=0) + button_canvas.grid(row=x, column=y, sticky="nsew", padx=3, pady=3) # Reduced gap between buttons + button_canvas.create_text(55, 27.5, text=textbtn, fill="white", font=('Arial', 21)) + button_canvas.create_rectangle(0, 0, 110, 55, outline="#36454F", width=5) # Slightly larger button + button_canvas.bind("", lambda event, textbtn=textbtn: self.on_button_click(textbtn)) + + def main(self, textbtn, x, y): + self.create_canvas_button(textbtn, x, y, bg_color="#0e0e1a") + self.button_frame.grid_rowconfigure(x, weight=1) + self.button_frame.grid_columnconfigure(y, weight=1) diff --git a/Calculator/Components/Calculator_Entry.py b/Calculator/Components/Calculator_Entry.py index 3c5c8ec..e488ca7 100644 --- a/Calculator/Components/Calculator_Entry.py +++ b/Calculator/Components/Calculator_Entry.py @@ -1,6 +1,16 @@ +# from tkinter import * + +# def result_input(root): +# r_input = Entry(root, font=("Arial", 24), bd=10, relief=FLAT, justify="left") +# r_input.grid(row=0, column=0, columnspan=4, ipadx=8, ipady=8, pady=10) +# return r_input + from tkinter import * def result_input(root): - r_input = Entry(root, font=("Arial", 24), bd=10, relief=FLAT, justify="left") - r_input.grid(row=0, column=0, columnspan=4, ipadx=8, ipady=8, pady=10) + # r_input = Entry(root, font=("Arial", 24), bd=10, relief=FLAT, justify="left") + # r_input.grid(row=0, column=0, columnspan=4, ipadx=8, ipady=8, pady=10,sticky="wsne") + r_input = Entry(root, font=("Arial", 18), bd=10, relief=FLAT, justify="left", width=10) + r_input.grid(row=0, column=0, columnspan=4, ipadx=5, ipady=5, pady=10, padx=10, sticky="ew") + return r_input \ No newline at end of file diff --git a/Calculator/Components/__pycache__/Calculator_Button.cpython-313.pyc b/Calculator/Components/__pycache__/Calculator_Button.cpython-313.pyc index fb03105..0e0e1cd 100644 Binary files a/Calculator/Components/__pycache__/Calculator_Button.cpython-313.pyc and b/Calculator/Components/__pycache__/Calculator_Button.cpython-313.pyc differ diff --git a/Calculator/Components/__pycache__/Calculator_Entry.cpython-313.pyc b/Calculator/Components/__pycache__/Calculator_Entry.cpython-313.pyc index 3d54d65..e15813c 100644 Binary files a/Calculator/Components/__pycache__/Calculator_Entry.cpython-313.pyc and b/Calculator/Components/__pycache__/Calculator_Entry.cpython-313.pyc differ diff --git a/Calculator/main.py b/Calculator/main.py index c8cedbd..78f3757 100644 --- a/Calculator/main.py +++ b/Calculator/main.py @@ -1,3 +1,34 @@ +# from tkinter import * +# from Components.Calculator_Entry import result_input +# from Components.Calculator_Button import CalculatorButtons + +# root = Tk() +# btns = [ '1', '2' , '3' , '-' , '4' , '5' , '6' , '*' , '7' , '8' , '9' , '+' , '0' ,'=' ,'/','CL'] + +# def main_fram(): +# root.title("Calculator") +# root.geometry('400x430') +# root.resizable(width=True,height=False) +# root.configure(bg="#34495E") + +# def buttons(entry): +# counter = 0 +# clubtn = CalculatorButtons(root, entry) +# for i in range(1,11,3): +# for j in range(4): +# clubtn.main(btns[counter],i,j) +# counter += 1 + +# def main(): +# main_fram() +# entry = result_input(root) +# buttons(entry) +# root.mainloop() + +# if __name__ == "__main__": +# main() + + from tkinter import * from Components.Calculator_Entry import result_input from Components.Calculator_Button import CalculatorButtons @@ -7,9 +38,9 @@ def main_fram(): root.title("Calculator") - root.geometry('400x430') - root.resizable(width=True,height=False) - root.configure(bg="#34495E") + root.geometry('505x375') + root.resizable(width=True,height=True) + root.configure(bg="#2A2A2A") def buttons(entry): counter = 0