From 90e48f835f34348931d3396bd9f464d6e9653d68 Mon Sep 17 00:00:00 2001 From: MohitHire Date: Mon, 23 Oct 2023 18:57:57 +0530 Subject: [PATCH 1/7] Add compund interest using python tkinter --- compound_Interest.py/compundinterest.py | 112 ++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 compound_Interest.py/compundinterest.py diff --git a/compound_Interest.py/compundinterest.py b/compound_Interest.py/compundinterest.py new file mode 100644 index 0000000..cfe1757 --- /dev/null +++ b/compound_Interest.py/compundinterest.py @@ -0,0 +1,112 @@ +# import all classes / functions from the tkinter +from tkinter import * + +# Function for clearing the +# contents of all entry boxes +def clear_all() : + + # whole content of entry boxes is deleted + principal_field.delete(0, END) + rate_field.delete(0, END) + time_field.delete(0, END) + compound_field.delete(0, END) + + # set focus on the principal_field entry box + principal_field.focus_set() + + +# Function to find compound interest +def calculate_ci(): + + # get a content from entry box + principal = int(principal_field.get()) + + rate = float(rate_field.get()) + + time = int(time_field.get()) + + # Calculates compound interest + CI = principal * (pow((1 + rate / 100), time)) + + # insert method inserting the + # value in the text entry box. + compound_field.insert(10, CI) + + + +# Driver code +if __name__ == "__main__" : + + # Create a GUI window + root = Tk() + + # Set the background colour of GUI window + root.configure(background = 'dark blue') + + # Set the configuration of GUI window + root.geometry("400x250") + + # set the name of tkinter GUI window + root.title("Compound Interest Calculator") + + # Create a Principal Amount : label + label1 = Label(root, text = "Principal Amount(Rs) : ", + fg = 'white', bg = 'red') + + # Create a Rate : label + label2 = Label(root, text = "Rate(%) : ", + fg = 'white', bg = 'red') + + # Create a Time : label + label3 = Label(root, text = "Time(years) : ", + fg = 'white', bg = 'red') + + # Create a Compound Interest : label + label4 = Label(root, text = "Compound Interest : ", + fg = 'white', bg = 'red') + + # grid method is used for placing + # the widgets at respective positions + # in table like structure . + + # padx keyword argument used to set padding along x-axis . + # pady keyword argument used to set padding along y-axis . + label1.grid(row = 1, column = 0, padx = 10, pady = 10) + label2.grid(row = 2, column = 0, padx = 10, pady = 10) + label3.grid(row = 3, column = 0, padx = 10, pady = 10) + label4.grid(row = 5, column = 0, padx = 10, pady = 10) + + # Create a entry box + # for filling or typing the information. + principal_field = Entry(root) + rate_field = Entry(root) + time_field = Entry(root) + compound_field = Entry(root) + + # grid method is used for placing + # the widgets at respective positions + # in table like structure . + + # padx keyword argument used to set padding along x-axis . + # pady keyword argument used to set padding along y-axis . + principal_field.grid(row = 1, column = 1, padx = 10, pady = 10) + rate_field.grid(row = 2, column = 1, padx = 10, pady = 10) + time_field.grid(row = 3, column = 1, padx = 10, pady = 10) + compound_field.grid(row = 5, column = 1, padx = 10, pady = 10) + + # Create a Submit Button and attached + # to calculate_ci function + button1 = Button(root, text = "Submit", bg = "red", + fg = "black", command = calculate_ci) + + # Create a Clear Button and attached + # to clear_all function + button2 = Button(root, text = "Clear", bg = "red", + fg = "black", command = clear_all) + + button1.grid(row = 4, column = 1, pady = 10) + button2.grid(row = 6, column = 1, pady = 10) + + # Start the GUI + root.mainloop() + \ No newline at end of file From af3ab91b8cddd77a780dae1f880073dbbcc14154 Mon Sep 17 00:00:00 2001 From: MohitHire Date: Wed, 25 Oct 2023 23:32:05 +0530 Subject: [PATCH 2/7] Add Pomodrone project using tkinter --- Pomodrone/pomodrone.py | 94 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 Pomodrone/pomodrone.py diff --git a/Pomodrone/pomodrone.py b/Pomodrone/pomodrone.py new file mode 100644 index 0000000..470d7fe --- /dev/null +++ b/Pomodrone/pomodrone.py @@ -0,0 +1,94 @@ +import tkinter as tk +from tkinter import messagebox +from PIL import Image, ImageTk +from playsound import playsound +import time + +class Pomodoro: + def __init__(self, root): + self.root = root + + def work_break(self, timer): + + # common block to display minutes + # and seconds on GUI + minutes, seconds = divmod(timer, 60) + self.min.set(f"{minutes:02d}") + self.sec.set(f"{seconds:02d}") + self.root.update() + time.sleep(1) + + def work(self): + timer = 25*60 + while timer >= 0: + pomo.work_break(timer) + if timer == 0: + + # once work is done play + # a sound and switch for break + playsound("sound.ogg") + messagebox.showinfo( + "Good Job", "Take A Break, \ + nClick Break Button") + timer -= 1 + + def break_(self): + timer = 5*60 + while timer >= 0: + pomo.work_break(timer) + if timer == 0: + + # once break is done, + # switch back to work + playsound("sound.ogg") + messagebox.showinfo( + "Times Up", "Get Back To Work, \ + nClick Work Button") + timer -= 1 + + def main(self): + + # GUI window configuration + self.root.geometry("450x455") + self.root.resizable(False, False) + self.root.title("Pomodoro Timer") + + # label + self.min = tk.StringVar(self.root) + self.min.set("25") + self.sec = tk.StringVar(self.root) + self.sec.set("00") + + self.min_label = tk.Label(self.root, + textvariable=self.min, font=( + "arial", 22, "bold"), bg="red", fg='black') + self.min_label.pack() + + self.sec_label = tk.Label(self.root, + textvariable=self.sec, font=( + "arial", 22, "bold"), bg="black", fg='white') + self.sec_label.pack() + + # add background image for GUI using Canvas widget + canvas = tk.Canvas(self.root) + canvas.pack(expand=True, fill="both") + img = Image.open('pomodoro.jpg') + bg = ImageTk.PhotoImage(img) + canvas.create_image(90, 10, image=bg, anchor="nw") + + # create three buttons with countdown function command + btn_work = tk.Button(self.root, text="Start", + bd=5, command=self.work, + bg="red", font=( + "arial", 15, "bold")).place(x=140, y=380) + btn_break = tk.Button(self.root, text="Break", + bd=5, command=self.break_, + bg="red", font=( + "arial", 15, "bold")).place(x=240, y=380) + + self.root.mainloop() + + +if __name__ == '__main__': + pomo = Pomodoro(tk.Tk()) + pomo.main() From 48e21e05142b118fa7895a68f2303347e148e3d7 Mon Sep 17 00:00:00 2001 From: RiyaaBhatt <128878008+RiyaaBhatt@users.noreply.github.com> Date: Fri, 26 Apr 2024 11:44:31 +0530 Subject: [PATCH 3/7] changes --- Email Sender/send_email.py | 233 +++++++++++++++++-------------------- 1 file changed, 109 insertions(+), 124 deletions(-) diff --git a/Email Sender/send_email.py b/Email Sender/send_email.py index 64a2ace..6db3573 100644 --- a/Email Sender/send_email.py +++ b/Email Sender/send_email.py @@ -1,150 +1,135 @@ from tkinter import * +from tkinter import ttk import tkinter as tk from PIL import ImageTk, Image from tkinter import messagebox import smtplib from tkinter.scrolledtext import ScrolledText - root = tk.Tk() +# Custom styles for hover effects +style = ttk.Style() +style.theme_use('clam') # You can choose a different theme if needed +style.map("C.TButton", + foreground=[('pressed', 'black'), ('active', 'blue')], + background=[('pressed', '!disabled', 'gray'), ('active', 'white')] +) +style.map("L.TButton", + foreground=[('pressed', 'black'), ('active', 'blue')], + background=[('pressed', '!disabled', 'gray'), ('active', 'orange')] +) -def Login(): - e = email.get() - p = password.get() - - if '@gmail.com' not in e or e == "" : - messagebox.showerror('Login error',"PLease Write the Valid Email") - elif p == "": - messagebox.showerror('Login error'," Password Shouldn't be Empty") - - else: - try: - - s = smtplib.SMTP('smtp.gmail.com', 587) - s.starttls() - s.login(e,p) #attempt to log into smtp server - messagebox.showinfo("Login Success","You have Logged to Gmail Successfully") - - - - - root = tk.Tk() - root.geometry('500x400') - - def Logout(): - s.quit() - root.destroy() - - - - header1 = Label(root,bg="orange",width=300,height=2) - header1.place(x=0,y=0) - - h2 = Label(root,text="Email Sender",bg="orange",fg="black",font= ('verdana',13,'bold')) - h2.place(x=175,y=5) - - logout = Button(root,text="Logout",padx=20,bg="orange",relief=RIDGE,borderwidth=1,font= ('verdana',10,'bold'),cursor="hand2",command=Logout) - logout.place(x=390,y=38) - - - - r = Label(root,text="Recipetent Email Address",font= ('verdana',10,'bold')) - r.place(x=130,y=130) - recipetent = Entry(root,width=30,relief=RIDGE,borderwidth=3) - recipetent.place(x=130,y=150) - - - - st = Label(root,text="Subject",font= ('verdana',10,'bold')) - st.place(x=130,y=190) - subject = Entry(root,width=30,relief=RIDGE,borderwidth=3) - subject.place(x=130,y=210) - - m = Label(root,text="Message",font= ('verdana',10,'bold')) - m.place(x=130,y=250) - - message = ScrolledText(root,width=40,height=5,relief=RIDGE,borderwidth=3) - message.place(x=130,y=270) - - - - def Send(): - r = recipetent.get() - st = subject.get() - m = message.get('1.0',END) - - if '@gmail.com' not in r or r == "": - messagebox.showerror('Sending Mail error',"Please Write the Valid Email") - elif m == "": - messagebox.showerror('Sending Mail error',"Message shouldn't be Empty") - - else: - s.sendmail(r,e,f'Subject :{st}\n\n {m}') - messagebox.showinfo("Success","Your Message has been send successfully") - - - - send = Button(root,text="Send",padx=30,relief=RIDGE,borderwidth=1,bg="orange",font= ('verdana',10,'bold'),cursor="hand2",command=Send) - send.place(x=350,y=360) - root.mainloop() - - - - - - - - - - except: - messagebox.showerror('Login error',"Failed to Login, Either Your Email or Password is Wrong nor You did Enable less secure Apps in gmail Setting") - - - - - +def on_enter(event): + event.widget.config(bg="orange") +def on_leave(event): + event.widget.config(bg="white") +def Login(): + e = email.get() + p = password.get() + + if '@gmail.com' not in e or e == "": + messagebox.showerror('Login error',"Please write a valid email") + elif p == "": + messagebox.showerror('Login error',"Password shouldn't be empty") + else: + try: + s = smtplib.SMTP('smtp.gmail.com', 587) + s.starttls() + s.login(e,p) + messagebox.showinfo("Login Success","You have logged into Gmail successfully") + root.withdraw() # Hide login window + + # Create the main window + main_window = tk.Toplevel() + main_window.geometry('500x400') + main_window.title('Email Sender') + + def Logout(): + s.quit() + main_window.destroy() + + header1 = Label(main_window, bg="orange", width=300, height=2) + header1.place(x=0, y=0) + + h2 = Label(main_window, text="Email Sender", bg="orange", fg="black", font=('verdana', 13, 'bold')) + h2.place(x=175, y=5) + + logout = ttk.Button(main_window, text="Logout", style="C.TButton", width=10, command=Logout) + logout.place(x=390, y=38) + + r = Label(main_window, text="Recipient Email Address", font=('verdana', 10, 'bold')) + r.place(x=130, y=130) + recipient = Entry(main_window, width=30, relief=RIDGE, borderwidth=3) + recipient.place(x=130, y=150) + + st = Label(main_window, text="Subject", font=('verdana', 10, 'bold')) + st.place(x=130, y=190) + subject = Entry(main_window, width=30, relief=RIDGE, borderwidth=3) + subject.place(x=130, y=210) + + m = Label(main_window, text="Message", font=('verdana', 10, 'bold')) + m.place(x=130, y=250) + + message = ScrolledText(main_window, width=40, height=5, relief=RIDGE, borderwidth=3) + message.place(x=130, y=270) + + def Send(): + r = recipient.get() + st = subject.get() + m = message.get('1.0', END) + + if '@gmail.com' not in r or r == "": + messagebox.showerror('Sending Mail error', "Please write a valid email") + elif m == "": + messagebox.showerror('Sending Mail error', "Message shouldn't be empty") + else: + s.sendmail(r, e, f'Subject :{st}\n\n {m}') + messagebox.showinfo("Success", "Your message has been sent successfully") + + send = ttk.Button(main_window, text="Send", style="C.TButton", width=10, command=Send) + send.place(x=350, y=360) + + main_window.mainloop() + + except: + messagebox.showerror('Login error', "Failed to login. Check your email or password.") root.title('Email Sender') root.geometry('400x300') root.maxsize(400,300) root.minsize(400,300) -header = Label(root,bg="orange",width=300,height=2) -header.place(x=0,y=0) +header = Label(root, bg="orange", width=300, height=2) +header.place(x=0, y=0) -h1 = Label(root,text="Email Sender",bg="orange",fg="black",font= ('verdana',13,'bold')) -h1.place(x=135,y=5) +h1 = Label(root, text="Email Sender", bg="orange", fg="black", font=('verdana', 13, 'bold')) +h1.place(x=135, y=5) img = ImageTk.PhotoImage(Image.open('gmail.png')) -logo = Label(root,image=img,borderwidth=0) -logo.place(x=150,y=38) - - -e = Label(root,text="Email Address",font= ('verdana',10,'bold')) -e.place(x=100,y=130) -email = Entry(root,width=30,relief=RIDGE,borderwidth=3) -email.place(x=100,y=150) - - - -p = Label(root,text="Password",font= ('verdana',10,'bold')) -p.place(x=100,y=190) -password = Entry(root,width=30,relief=RIDGE,borderwidth=3) -password.place(x=100,y=210) - - -login = Button(root,text="Login",padx=30,bg="orange",relief=RIDGE,borderwidth=1,font= ('verdana',10,'bold'),cursor="hand2",command=Login) -login.place(x=135,y=240) - - - - - +logo = Label(root, image=img, borderwidth=0) +logo.place(x=150, y=38) + +e = Label(root, text="Email Address", font=('verdana', 10, 'bold')) +e.place(x=100, y=130) +email = Entry(root, width=30, relief=RIDGE, borderwidth=3, font=('Arial', 10)) # Changed font here +email.place(x=100, y=150) +email.bind("", on_enter) +email.bind("", on_leave) + +p = Label(root, text="Password", font=('verdana', 10, 'bold')) +p.place(x=100, y=190) +password = Entry(root, width=30, relief=RIDGE, borderwidth=3, font=('Arial', 10)) # Changed font here +password.place(x=100, y=210) +password.bind("", on_enter) +password.bind("", on_leave) + +login = ttk.Button(root, text="Login", style="L.TButton", width=10, command=Login) # Changed style here +login.place(x=145, y=240) root.mainloop() From 532979299c887e7b61ff7f764516751842a81ae3 Mon Sep 17 00:00:00 2001 From: Joao Angelo <78273535+Joao-Angelo-P@users.noreply.github.com> Date: Sat, 8 Mar 2025 18:24:56 -0400 Subject: [PATCH 4/7] Simple Calculator Calculator app with ".pack()" for geometry layout. For layout more concise, add widgets inside a Frame and this Frame inside the main window(Frame or Tk or Toplevel).The refence in the first comment. --- calculator/calculator2.py | 55 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 calculator/calculator2.py diff --git a/calculator/calculator2.py b/calculator/calculator2.py new file mode 100644 index 0000000..dda9abc --- /dev/null +++ b/calculator/calculator2.py @@ -0,0 +1,55 @@ +# Inspirado no programa 'clac1.py' do livro "Python and Tkinter Programming" de John E.Grayson +from tkinter import * + +def frame(root, side): + w = Frame(master=root) + w.pack(side=side, expand=True, fill=BOTH, padx=(5, 0)) + return w + +def button(root, text, side, command=None, **kw): + w = Button(master=root, text=text, + command=command, relief=RIDGE, **kw) + w.pack(side=side, expand=True, fill=BOTH) + return w + +root = Frame() +display = StringVar() +frame_top = Frame(root,) +frame_top.pack(side=TOP, fill=BOTH, expand=YES) +Entry(master=frame_top, relief=SUNKEN, + textvariable=display).pack(side=LEFT, expand=YES, fill=BOTH, padx=5, pady=2) +Button(frame_top, text="C", + command=lambda w=display: w.set(''), + bg="red", fg="white", relief=RIDGE).pack(side=RIGHT, expand=False, padx=2) + + +for i in "987+ 654- 321* 0d./".split(): + frame2buttons = frame(root, TOP) + for char in i: + if char == "d": + button(frame2buttons, "00", LEFT, + lambda w=display: w.set(w.get()+"00")) + else: + + button(frame2buttons,char,LEFT, + lambda w=display, c='%s' % char: w.set(w.get()+c)) + + +def result(w, e=None): + s = w.get() + if '%' in s: + index = list(s).index('%') + list_s = list(s) + list_s.insert(0, '(') + list_s.insert(index+1, ')/100') + list_s[index+2] = '*' + s = ''.join(list_s) + + w.set(eval(s)) + +frame_bottom = frame(root, BOTTOM) +button(frame_bottom, "=", LEFT, command=lambda w=display: result(w), bg="red", fg="white") +Button(master=frame_bottom, text="%", relief=RIDGE, command=lambda w=display: w.set(w.get()+"%")).pack(side=LEFT, expand=False) + +root.pack(side=TOP, fill=BOTH, expand=True) +root.mainloop() From ebb9572628d9e946cad0ceefa3be978a3ad77f4a Mon Sep 17 00:00:00 2001 From: Joao Angelo <78273535+Joao-Angelo-P@users.noreply.github.com> Date: Mon, 31 Mar 2025 10:56:59 -0400 Subject: [PATCH 5/7] Update calculator2.py Disabled the user input in Entry widget. For force the user use only buttons entry data. --- calculator/calculator2.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/calculator/calculator2.py b/calculator/calculator2.py index dda9abc..6f12343 100644 --- a/calculator/calculator2.py +++ b/calculator/calculator2.py @@ -1,5 +1,7 @@ # Inspirado no programa 'clac1.py' do livro "Python and Tkinter Programming" de John E.Grayson from tkinter import * +if 'constants' not in __import__('tkinter').__all__: + from tkinter import constants def frame(root, side): w = Frame(master=root) @@ -17,7 +19,7 @@ def button(root, text, side, command=None, **kw): frame_top = Frame(root,) frame_top.pack(side=TOP, fill=BOTH, expand=YES) Entry(master=frame_top, relief=SUNKEN, - textvariable=display).pack(side=LEFT, expand=YES, fill=BOTH, padx=5, pady=2) + textvariable=display, state=constants.DISABLED).pack(side=LEFT, expand=YES, fill=BOTH, padx=5, pady=2) Button(frame_top, text="C", command=lambda w=display: w.set(''), bg="red", fg="white", relief=RIDGE).pack(side=RIGHT, expand=False, padx=2) From a5ba37dfeeba4302e53bbb5469fcd82cf2601f7c Mon Sep 17 00:00:00 2001 From: Joao Angelo <78273535+Joao-Angelo-P@users.noreply.github.com> Date: Mon, 31 Mar 2025 11:18:14 -0400 Subject: [PATCH 6/7] Update calculator2.py Exclude the "from tkinter import constants", forgot already have. --- calculator/calculator2.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/calculator/calculator2.py b/calculator/calculator2.py index 6f12343..1c4faf3 100644 --- a/calculator/calculator2.py +++ b/calculator/calculator2.py @@ -1,7 +1,5 @@ # Inspirado no programa 'clac1.py' do livro "Python and Tkinter Programming" de John E.Grayson from tkinter import * -if 'constants' not in __import__('tkinter').__all__: - from tkinter import constants def frame(root, side): w = Frame(master=root) From 73429e66fac4af8f19a155e16996e0966cc116c2 Mon Sep 17 00:00:00 2001 From: Joao Angelo <78273535+Joao-Angelo-P@users.noreply.github.com> Date: Mon, 31 Mar 2025 12:44:42 -0400 Subject: [PATCH 7/7] Update calculator2.py only "state=DISABLED". --- calculator/calculator2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/calculator/calculator2.py b/calculator/calculator2.py index 1c4faf3..93678c4 100644 --- a/calculator/calculator2.py +++ b/calculator/calculator2.py @@ -17,7 +17,7 @@ def button(root, text, side, command=None, **kw): frame_top = Frame(root,) frame_top.pack(side=TOP, fill=BOTH, expand=YES) Entry(master=frame_top, relief=SUNKEN, - textvariable=display, state=constants.DISABLED).pack(side=LEFT, expand=YES, fill=BOTH, padx=5, pady=2) + textvariable=display, state=DISABLED).pack(side=LEFT, expand=YES, fill=BOTH, padx=5, pady=2) Button(frame_top, text="C", command=lambda w=display: w.set(''), bg="red", fg="white", relief=RIDGE).pack(side=RIGHT, expand=False, padx=2)