From ea663ccf4a7f82b9c2647424ee2cdf50e314a29f Mon Sep 17 00:00:00 2001 From: Deepraj Baidya <63138398+deepraj02@users.noreply.github.com> Date: Sat, 5 Dec 2020 16:30:06 +0530 Subject: [PATCH 1/2] Better UI better experience made the GUI better with updated code base and fast execution... --- calculator.py | 252 +++++++++++++++++++++++++++----------------------- 1 file changed, 136 insertions(+), 116 deletions(-) diff --git a/calculator.py b/calculator.py index 3dedd70..203fc37 100644 --- a/calculator.py +++ b/calculator.py @@ -1,117 +1,137 @@ from tkinter import * - - -class calculate(): - - def __init__(self): - self.root = Tk() - self.root.title("Calculator") - self.root.geometry("370x220") - - self.resultwindow = Entry(self.root) - self.resultwindow.grid(row=0,column=0,columnspan=6) - self.resultwindow.config(font=("Arial", 18)) - self.resultwindow.focus_set() # Sets focus on the input text area - - # Buttons - self.button1 = Button(self.root, text="1", width=3, command=lambda:self.ins('1')) - self.button1.grid(row=1,column=0, padx=3, pady=3) - self.button1.config(font=("Arial", 18)) - - self.button2 = Button(self.root, text="2", width=3, command=lambda:self.ins('2')) - self.button2.grid(row=1, column=1, padx=3, pady=3) - self.button2.config(font=("Arial", 18)) - - self.button3 = Button(self.root, text="3", width=3, command=lambda:self.ins('3')) - self.button3.grid(row=1, column=2, padx=3, pady=3) - self.button3.config(font=("Arial", 18)) - - self.button4 = Button(self.root, text="4", width=3, command=lambda:self.ins('4')) - self.button4.grid(row=2, column=0, padx=3, pady=3) - self.button4.config(font=("Arial", 18)) - - self.button5 = Button(self.root, text="5", width=3, command=lambda:self.ins('5')) - self.button5.grid(row=2, column=1, padx=3, pady=3) - self.button5.config(font=("Arial", 18)) - - self.button6 = Button(self.root, text="6", width=3, command=lambda:self.ins('6')) - self.button6.grid(row=2, column=2, padx=3, pady=3) - self.button6.config(font=("Arial", 18)) - - self.button7 = Button(self.root, text="7", width=3, command=lambda:self.ins('7')) - self.button7.grid(row=3, column=0, padx=3, pady=3) - self.button7.config(font=("Arial", 18)) - - self.button8 = Button(self.root, text="8", width=3, command=lambda:self.ins('8')) - self.button8.grid(row=3, column=1, padx=3, pady=3) - self.button8.config(font=("Arial", 18)) - - self.button9 = Button(self.root, text="9", width=3, command=lambda:self.ins('9')) - self.button9.grid(row=3, column=2, padx=3, pady=3) - self.button9.config(font=("Arial", 18)) - - self.button0 = Button(self.root, text="0", width=3, command=lambda: self.ins('0')) - self.button0.grid(row=4, column=0, padx=3, pady=3) - self.button0.config(font=("Arial", 18)) - - self.button_open = Button(self.root, text="(", width=3, command=lambda: self.ins('(')) - self.button_open.grid(row=4, column=1, padx=3, pady=3) - self.button_open.config(font=("Arial", 18)) - - self.button_close = Button(self.root, text=")", width=3, command=lambda: self.ins(')')) - self.button_close.grid(row=4, column=2, padx=3, pady=3) - self.button_close.config(font=("Arial", 18)) - - # Operations Buttons - - self.buttonplus = Button(self.root, text="+", width=3, command=lambda:self.ins('+')) - self.buttonplus.grid(row=1, column=3, padx=3, pady=3) - self.buttonplus.config(font=("Arial", 18)) - - self.buttonminus = Button(self.root, text="-", width=3, command=lambda:self.ins('-')) - self.buttonminus.grid(row=1, column=4, padx=3, pady=3) - self.buttonminus.config(font=("Arial", 18)) - - self.buttondivide = Button(self.root, text="/", width=3, command=lambda:self.ins('/')) - self.buttondivide.grid(row=2, column=3, padx=3, pady=3) - self.buttondivide.config(font=("Arial", 18)) - - self.buttonmultiply = Button(self.root, text="*", width=3, command=lambda:self.ins('*')) - self.buttonmultiply.grid(row=2, column=4, padx=3, pady=3) - self.buttonmultiply.config(font=("Arial", 18)) - - self.buttoncancel = Button(self.root, text="C", width=3, command=lambda: self.cancel()) - self.buttoncancel.grid(row=3, column=4, padx=3, pady=3) - self.buttoncancel.config(font=("Arial", 18)) - - self.buttondeleteall = Button(self.root, text="Del", width=3, command=lambda: self.delete_all()) - self.buttondeleteall.grid(row=3, column=3, padx=3, pady=3) - self.buttondeleteall.config(font=("Arial", 18)) - - self.buttonresult = Button(self.root, text="=", width=6, command=lambda:self.calculate()) - self.buttonresult.grid(row=4, column=3, padx=3, pady=3, columnspan=2) - self.buttonresult.config(font=("Arial", 18)) - - self.root.mainloop() - - def ins(self,val): - self.resultwindow.insert(END, val) - - def cancel(self): - self.resultwindow.delete(0, 'end') - - def delete_all(self): - x = self.resultwindow.get() - self.resultwindow.delete(0, 'end') - y = x[:-1] - self.resultwindow.insert(0, y) - - def calculate(self): - x = self.resultwindow.get() - answer = eval(x) - self.resultwindow.delete(0, 'end') - self.resultwindow.insert(0, answer) - - -if __name__ == "__main__": - calculate() +import tkinter.messagebox as tmb + +#& All functions +def click(event): + global scvalue + text = event.widget.cget("text") + if text == "=": + if scvalue.get().isdigit(): + value = int(scvalue.get()) + else: + try: + value = eval(screen.get()) + + except Exception as e: + print(e) + err=tmb.showerror("ERROR ENCOUNTERED","SORRY, An Error Occured,\n Please Check Your Input.") + scvalue.set(value) + screen.update() + + elif text == "C": + scvalue.set("") + screen.update() + + else: + scvalue.set(scvalue.get() + text) + screen.update() #@ to update the screen with the widgets pressed + + +root=Tk() +root.geometry("390x498") +root.minsize(390,498) +root.maxsize(390,498) +root.title("GUI Calculator -By Deepraj") +root.wm_iconbitmap("calculator_14445.ico") + + + + +#$ Moving to Screen +scvalue=StringVar() +scvalue.set("") +screen=Entry(root,textvar=scvalue,font="Comicsansms 30",bg="#B5BABA",relief=SUNKEN) +screen.pack(pady=10,padx=4) + +#^ BAsic +f1=Frame(root,bg="#EE5537",height=20,width=30) +b=Button(f1,text="C",font="consolas 19",bg="#E8F2E6",width=8) +b.pack(side=LEFT,padx=3,pady=2,anchor=W) +b.bind("",click) +b=Button(f1,text="/",font="consolas 19",bg="#E8F2E6",width=8) +b.pack(side=LEFT,padx=3,pady=2,anchor=E) +b.bind("",click) +b=Button(f1,text="-",font="consolas 19",bg="#E8F2E6",width=8) +b.pack(side=LEFT,padx=3,pady=2,anchor=E) +b.bind("",click) + +f1.pack(anchor=NW) + +f1=Frame(root,bg="#EE5537",height=20,width=30) + +b=Button(f1,text="+",font="consolas 19",bg="#E8F2E6",width=8) +b.pack(side=LEFT,padx=3,pady=2,anchor=E) +b.bind("",click) +b=Button(f1,text="*",font="consolas 19",bg="#E8F2E6",width=8) +b.pack(side=LEFT,padx=3,pady=2,anchor=W) +b.bind("",click) +b=Button(f1,text="=",font="consolas 19",bg="#E8F2E6",width=8) +b.pack(side=LEFT,padx=3,pady=2,anchor=W) +b.bind("",click) +f1.pack(anchor=NW) + + +#! First Row Buttons +f1=Frame(root,bg="#EE5537",height=20,width=30) +b=Button(f1,text="7",font="consolas 19",bg="#E8F2E6",width=8) +b.pack(side=LEFT,padx=3,pady=2,anchor=W) +b.bind("",click) +b=Button(f1,text="8",font="consolas 19",bg="#E8F2E6",width=8) +b.pack(side=LEFT,padx=3,pady=2,anchor=W) +b.bind("",click) +b=Button(f1,text="9",font="consolas 19",bg="#E8F2E6",width=8) +b.pack(side=LEFT,padx=3,pady=2,anchor=W) +b.bind("",click) +f1.pack(anchor=NW) + +#^ Second row Buttons + +f1=Frame(root,bg="#EE5537",height=20,width=30) +b=Button(f1,text="4",font="consolas 19",bg="#E8F2E6",width=8) +b.pack(side=LEFT,padx=3,pady=2,anchor=W) +b.bind("",click) +b=Button(f1,text="5",font="consolas 19",bg="#E8F2E6",width=8) +b.pack(side=LEFT,padx=3,pady=2,anchor=W) +b.bind("",click) +b=Button(f1,text="6",font="consolas 19",bg="#E8F2E6",width=8) +b.pack(side=LEFT,padx=3,pady=2,anchor=W) +b.bind("",click) +f1.pack(anchor=NW) + +#* Third row Buttons +f1=Frame(root,bg="#EE5537",padx=0,height=20,width=30) +b=Button(f1,text="1",font="consolas 19",bg="#E8F2E6",width=8) +b.pack(side=LEFT,padx=3,pady=2,anchor=W) +b.bind("",click) +b=Button(f1,text="2",font="consolas 19",bg="#E8F2E6",width=8) +b.pack(side=LEFT,padx=3,pady=2,anchor=W) +b.bind("",click) +b=Button(f1,text="3",font="consolas 19",bg="#E8F2E6",width=8) +b.pack(side=LEFT,padx=3,pady=2,anchor=W) +b.bind("",click) +f1.pack(anchor=NW) + +#@ Fourth row Buttons +f1=Frame(root,bg="#EE5537",height=20,width=20) +b=Button(f1,text="00",font="consolas 19",bg="#E8F2E6",width=8) +b.pack(side=LEFT,padx=3,pady=2,anchor=W) +b.bind("",click) +b=Button(f1,text="0",font="consolas 19",bg="#E8F2E6",width=8) +b.pack(side=LEFT,padx=3,pady=2,anchor=W) +b.bind("",click) +b=Button(f1,text=".",font="consolas 19",bg="#E8F2E6",width=8) +b.pack(side=LEFT,padx=3,pady=2,anchor=W) +b.bind("",click) +f1.pack(anchor=NW) + +#% Thanks Func +def thanks(): + tmb.showinfo("Feedback-Window","Would you like to give us a 5⭐\n Enjoy Your day....") + +#$ Thanks Note +f1=Frame(root,bg="#EE5537",height=10,width=15) +b=Button(f1,text="Share your\nExperience⭐",font="consolas 19",bg="#E8F2E6",width=12,command=thanks) +b.pack(side=BOTTOM,padx=3,pady=4,anchor=W) +f1.pack(anchor=S) + +root.mainloop() From 3c6ed240826b3801142a4ac53885093e95b5b388 Mon Sep 17 00:00:00 2001 From: Deepraj Baidya <63138398+deepraj02@users.noreply.github.com> Date: Mon, 28 Dec 2020 20:07:02 +0530 Subject: [PATCH 2/2] Major fixes and Changes - Updated the code - Updated the UI - Included README --- README.md | 27 +++++++- calculator_14445.ico | Bin 0 -> 67646 bytes main.py | 144 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 169 insertions(+), 2 deletions(-) create mode 100644 calculator_14445.ico create mode 100644 main.py diff --git a/README.md b/README.md index 60613d5..a2cbf08 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,25 @@ -# GUI-scientific-calculator-using-python -it's a scientific calculator using python.It will consist a graphical user interface using Tkinter libraries in python. +Hey Guys it's a python GUI (Made with Tkinter) Calculator project. + +To Create the Application:- + 1) Importing the module – tkinter + 2) Create the main window (container) + 3) Add any number of widgets to the main window + 4) Apply the event Trigger on the widgets. + +Let’s create a GUI based simple calculator using Python Tkinter module, which can perform basic arithmatic operations addition, subtraction, multiplication and division. + +Have a Look at my code (main.py)...... + +Follow Me on :--- + + #GitHub - https://github.com/deepraj02 + + #Instagram - https://www.instagram.com/deeprajbaidya02/?hl=en + +Thanks, +HAPPY CODING........ + + +With Regards, + +Deepraj Baidya. diff --git a/calculator_14445.ico b/calculator_14445.ico new file mode 100644 index 0000000000000000000000000000000000000000..de5ffdeb5eeb0481080abac2ef0edf59dfe73ffe GIT binary patch literal 67646 zcmeHQdyG{_89$^ZXiW4E6Z?lI7*o4_W;9ePJ=9)5j#d!p~n zjzoUEy*2-Qdm_I9-1l{~) zFZ65YY%_32?4A68Cnn+dTi}aTT^IL%HEQ&VdU>x;9Q+)%ZNwY!d(RGEyLY+FuzvNd z#~opA#}~i{XAFL5>088 z?Z2XNN;FRjS#8S&DBnT0k2=BAO_=NEZkLX`l@H49{8&5m5A(IcCz=OIcQx(0XxDTc z$ANsGaD%CnusF`UX7-kVu%8-Nwzu|8bhPyS@X{}C`II~A#5c6j-ZKYQ0!E(Wj=Ygg z7xaZQHw2D7Ef+zGgsbvo5FpOVL6@rU{2=4P2YX3Mg^?s>ZtURgY6D8y}^&3~vz z=tvCQ&TcW$_r*5flP(Q8!LQyhsMA?AYjfnVr{xgv!BcUQ1xr(<1<=nkb?^0JZH>1q zy&rTs>m!Xl;R6^SzR_{M;_tMlJ80QVd0{aRNfG)8!k-s;p zJb*e|V@-y!-bQ2B=yQ4Pj@_pcT1NSfYYS1+B`=@-!i6C34>gLdU3^F%bUIsO)#kZ; zn#jNO&9AKcLKI{{cFsr(U?WABL--+^DZtv@#^%7@T$hG%;cK0(kIo7+4^t&mqWWhD+6B!;-kOLnqNaW{- zNe-AYUn=%d)agj%fiq!|1F~hlq0^cDL{s(kPWUDaeSta7mp0ZbuiXtQ>^Wl)91{jL zFEDJfB+l`=Q_sXsr{knuyAA_$!yxnnGIcw&J+^ClaN0_o(?K1PpX0%7x^xd2lY4nb zosL_3>^S4p%ZdLE3m0*9~Q^9fREWeEl9}{_-m}=`TJ1 zd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?tR{@=X`HhpWS1;MUz+9e=t}d`^ z{+XJf;e0$ZM*AhCHVVWb}Ddfo5QOQ~~Cro668|PGx9h zM^VJcj_Od%F13=ujB@-+jaHZ4l?+TLA+ecUCBaG$Z6-jXn", click) +b = Button(f1, text="/", font="consolas 19", bg="#E8F2E6", width=8) +b.pack(side=LEFT, padx=3, pady=2, anchor=E) +b.bind("", click) +b = Button(f1, text="-", font="consolas 19", bg="#E8F2E6", width=8) +b.pack(side=LEFT, padx=3, pady=2, anchor=E) +b.bind("", click) + +f1.pack(anchor=NW) + +f1 = Frame(root, bg="#EE5537", height=20, width=30) + +b = Button(f1, text="+", font="consolas 19", bg="#E8F2E6", width=8) +b.pack(side=LEFT, padx=3, pady=2, anchor=E) +b.bind("", click) +b = Button(f1, text="*", font="consolas 19", bg="#E8F2E6", width=8) +b.pack(side=LEFT, padx=3, pady=2, anchor=W) +b.bind("", click) +b = Button(f1, text="=", font="consolas 19", bg="#E8F2E6", width=8) +b.pack(side=LEFT, padx=3, pady=2, anchor=W) +b.bind("", click) +f1.pack(anchor=NW) + + +#! First Row Buttons +f1 = Frame(root, bg="#EE5537", height=20, width=30) +b = Button(f1, text="7", font="consolas 19", bg="#E8F2E6", width=8) +b.pack(side=LEFT, padx=3, pady=2, anchor=W) +b.bind("", click) +b = Button(f1, text="8", font="consolas 19", bg="#E8F2E6", width=8) +b.pack(side=LEFT, padx=3, pady=2, anchor=W) +b.bind("", click) +b = Button(f1, text="9", font="consolas 19", bg="#E8F2E6", width=8) +b.pack(side=LEFT, padx=3, pady=2, anchor=W) +b.bind("", click) +f1.pack(anchor=NW) + +# ^ Second row Buttons + +f1 = Frame(root, bg="#EE5537", height=20, width=30) +b = Button(f1, text="4", font="consolas 19", bg="#E8F2E6", width=8) +b.pack(side=LEFT, padx=3, pady=2, anchor=W) +b.bind("", click) +b = Button(f1, text="5", font="consolas 19", bg="#E8F2E6", width=8) +b.pack(side=LEFT, padx=3, pady=2, anchor=W) +b.bind("", click) +b = Button(f1, text="6", font="consolas 19", bg="#E8F2E6", width=8) +b.pack(side=LEFT, padx=3, pady=2, anchor=W) +b.bind("", click) +f1.pack(anchor=NW) + +# * Third row Buttons +f1 = Frame(root, bg="#EE5537", padx=0, height=20, width=30) +b = Button(f1, text="1", font="consolas 19", bg="#E8F2E6", width=8) +b.pack(side=LEFT, padx=3, pady=2, anchor=W) +b.bind("", click) +b = Button(f1, text="2", font="consolas 19", bg="#E8F2E6", width=8) +b.pack(side=LEFT, padx=3, pady=2, anchor=W) +b.bind("", click) +b = Button(f1, text="3", font="consolas 19", bg="#E8F2E6", width=8) +b.pack(side=LEFT, padx=3, pady=2, anchor=W) +b.bind("", click) +f1.pack(anchor=NW) + +# @ Fourth row Buttons +f1 = Frame(root, bg="#EE5537", height=20, width=20) +b = Button(f1, text="00", font="consolas 19", bg="#E8F2E6", width=8) +b.pack(side=LEFT, padx=3, pady=2, anchor=W) +b.bind("", click) +b = Button(f1, text="0", font="consolas 19", bg="#E8F2E6", width=8) +b.pack(side=LEFT, padx=3, pady=2, anchor=W) +b.bind("", click) +b = Button(f1, text=".", font="consolas 19", bg="#E8F2E6", width=8) +b.pack(side=LEFT, padx=3, pady=2, anchor=W) +b.bind("", click) +f1.pack(anchor=NW) + +# % Thanks Func + + +def thanks(): + tmb.showinfo("Feedback-Window", + "Would you like to give us a 5⭐\n Enjoy Your day....") + + +# $ Thanks Note +f1 = Frame(root, bg="#EE5537", height=10, width=15) +b = Button(f1, text="Share your\nExperience⭐", font="consolas 19", + bg="#E8F2E6", width=12, command=thanks) +b.pack(side=BOTTOM, padx=3, pady=4, anchor=W) +f1.pack(anchor=S) + +root.mainloop()