From 29491be246f030077a8fc563e2d068412a3d1f58 Mon Sep 17 00:00:00 2001 From: BPM17 Date: Wed, 6 Aug 2025 19:22:01 -0600 Subject: [PATCH 1/3] Calculator buttons and screen are placed, no action yet --- .../{ => Calculator-App}/Calculator-App.md | 0 .../Calculator-App/Calculator-App.py | 54 +++++++++++++++++++ Projects/1-Beginner/Calculator-App/try.py | 30 +++++++++++ 3 files changed, 84 insertions(+) rename Projects/1-Beginner/{ => Calculator-App}/Calculator-App.md (100%) create mode 100644 Projects/1-Beginner/Calculator-App/Calculator-App.py create mode 100644 Projects/1-Beginner/Calculator-App/try.py diff --git a/Projects/1-Beginner/Calculator-App.md b/Projects/1-Beginner/Calculator-App/Calculator-App.md similarity index 100% rename from Projects/1-Beginner/Calculator-App.md rename to Projects/1-Beginner/Calculator-App/Calculator-App.md diff --git a/Projects/1-Beginner/Calculator-App/Calculator-App.py b/Projects/1-Beginner/Calculator-App/Calculator-App.py new file mode 100644 index 00000000..5aad406f --- /dev/null +++ b/Projects/1-Beginner/Calculator-App/Calculator-App.py @@ -0,0 +1,54 @@ +import ttkbootstrap as ttk +import tkinter as tk + +class Main(ttk.Window): + def __init__(self, title, dimensions): + super().__init__(self) + self.title(title) + self.geometry(dimensions) + + def __str__(self): + return super().__str__() + +class Calculator(): + def __init__(self, title, dimensions): + self.main = Main(title, dimensions) + # The calculator count with 20 buttons 1 big label at the top + # 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.mainFrame = ttk.Frame(self.main, height=400, width=300) + self.mainFrame.pack(padx=5, pady=5, fill="both", expand=True) + self.buttonsSimbols=["A/C", "+/-", "/", "<-", "7","8","9","x", "4","5","6","-", "1","2","3","+", "0", ".", "="] + self.Configure() + self.screenFrame = ttk.Frame(self.mainFrame) + self.screenFrame.pack(padx=0, pady=0, expand=True) + self.buttonsFrame = ttk.Frame(self.mainFrame) + self.buttonsFrame.pack(padx=0, pady=0, expand=True) + self.screen = ttk.Label(self.screenFrame, text="HOLA MUNDO", font=("Arial", 20, "bold"),justify="right") + self.screen.pack(padx=10, pady=10, expand=True) + self.GridButtons() + + self.main.mainloop() + + def GridButtons(self): + l= 0 + 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) + l +=1 + + def Configure(self): + for i in range(5): + self.mainFrame.rowconfigure(i, weight=1) + for i in range(4): + self.mainFrame.columnconfigure(i, weight=1) + + def __str__(self): + return super().__str__() + + +if __name__=="__main__": + calc = Calculator("Calculator", "300x400") \ No newline at end of file diff --git a/Projects/1-Beginner/Calculator-App/try.py b/Projects/1-Beginner/Calculator-App/try.py new file mode 100644 index 00000000..2bab44d5 --- /dev/null +++ b/Projects/1-Beginner/Calculator-App/try.py @@ -0,0 +1,30 @@ +def sorted(word): + print(word) + word = list(word) + print(type(word), word) + word.sort() + print(word) + sortedword = "" + for i in word: + sortedword = sortedword + i + return sortedword + +def ranks(arr): + res = [] + for i in range(len(arr)): + res.append(1) + for j in range(len(arr)): + if (arr[i] > arr[j]) == False and arr[i] != arr[j]: + res[i] = res[i] +1 + # elif + print(res) + + + + + + + +arr = [2,4,5,1,1,6,8,4,5] + +res = ranks(arr) \ No newline at end of file From 4984c5f68b95829a61950ee7cc2ccede819717d6 Mon Sep 17 00:00:00 2001 From: BPM17 Date: Wed, 6 Aug 2025 19:35:08 -0600 Subject: [PATCH 2/3] Theme changed --- .../Calculator-App/Calculator-App.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Projects/1-Beginner/Calculator-App/Calculator-App.py b/Projects/1-Beginner/Calculator-App/Calculator-App.py index 5aad406f..7d3f8afe 100644 --- a/Projects/1-Beginner/Calculator-App/Calculator-App.py +++ b/Projects/1-Beginner/Calculator-App/Calculator-App.py @@ -3,7 +3,7 @@ import tkinter as tk class Main(ttk.Window): def __init__(self, title, dimensions): - super().__init__(self) + super().__init__(self, themename="darkly") self.title(title) self.geometry(dimensions) @@ -17,20 +17,23 @@ 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.mainFrame = ttk.Frame(self.main, height=400, width=300) - self.mainFrame.pack(padx=5, pady=5, fill="both", expand=True) self.buttonsSimbols=["A/C", "+/-", "/", "<-", "7","8","9","x", "4","5","6","-", "1","2","3","+", "0", ".", "="] - self.Configure() - self.screenFrame = ttk.Frame(self.mainFrame) - self.screenFrame.pack(padx=0, pady=0, expand=True) - self.buttonsFrame = ttk.Frame(self.mainFrame) - self.buttonsFrame.pack(padx=0, pady=0, expand=True) + 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) + self.Configure() self.GridButtons() self.main.mainloop() + def CreateFrames(self): + self.mainFrame = ttk.Frame(self.main, height=400, width=300) + self.mainFrame.pack(padx=5, pady=5, fill="both", expand=True) + self.screenFrame = ttk.Frame(self.mainFrame) + self.screenFrame.pack(padx=0, pady=0, expand=True) + self.buttonsFrame = ttk.Frame(self.mainFrame) + self.buttonsFrame.pack(padx=0, pady=0, expand=True) + def GridButtons(self): l= 0 for j in range (6): From b3da3e04d1eb3939e2dcde88cc2848d52b902eee Mon Sep 17 00:00:00 2001 From: BPM17 Date: Thu, 7 Aug 2025 21:38:20 -0600 Subject: [PATCH 3/3] The calculator display the numbers when the buttons clicked, it does the first operations, but there are some issues --- .../Calculator-App/Calculator-App.py | 42 ++++++++++++++++--- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/Projects/1-Beginner/Calculator-App/Calculator-App.py b/Projects/1-Beginner/Calculator-App/Calculator-App.py index 7d3f8afe..84e6ed11 100644 --- a/Projects/1-Beginner/Calculator-App/Calculator-App.py +++ b/Projects/1-Beginner/Calculator-App/Calculator-App.py @@ -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("", 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__()