Skip to content

Commit 14e4a6b

Browse files
authored
Update calculator.py
1. Layout Fixed 2. Default Layout is Set. 3. Users can't change the size of the output window. 4. Appearance changed. Looks more attractive and the color codes used for buttons. 5. Padding is added. And few more changes.
1 parent a42b89a commit 14e4a6b

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

calculator.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,89 +6,93 @@ class calculate():
66
def __init__(self):
77
self.root = Tk()
88
self.root.title("Calculator")
9-
self.root.geometry("370x220")
9+
self.root.geometry("290x260")
1010

11-
self.resultwindow = Entry(self.root)
12-
self.resultwindow.grid(row=0,column=0,columnspan=6)
11+
self.root.maxsize(290, 260)
12+
self.root.minsize(290, 260)
13+
self.root.config(bg="grey")
14+
15+
self.resultwindow = Entry(self.root,borderwidth=5, relief=SUNKEN)
16+
self.resultwindow.grid(row=0,column=0,columnspan=6,pady=5)
1317
self.resultwindow.config(font=("Arial", 18))
1418
self.resultwindow.focus_set() # Sets focus on the input text area
1519

1620
# Buttons
17-
self.button1 = Button(self.root, text="1", width=3, command=lambda:self.ins('1'))
21+
self.button1 = Button(self.root, text="1", width=3, command=lambda:self.ins('1'),relief=RAISED,bg='light green')
1822
self.button1.grid(row=1,column=0, padx=3, pady=3)
1923
self.button1.config(font=("Arial", 18))
2024

21-
self.button2 = Button(self.root, text="2", width=3, command=lambda:self.ins('2'))
25+
self.button2 = Button(self.root, text="2", width=3, command=lambda:self.ins('2'),relief=RAISED,bg='light green')
2226
self.button2.grid(row=1, column=1, padx=3, pady=3)
2327
self.button2.config(font=("Arial", 18))
2428

25-
self.button3 = Button(self.root, text="3", width=3, command=lambda:self.ins('3'))
29+
self.button3 = Button(self.root, text="3", width=3, command=lambda:self.ins('3'),relief=RAISED,bg='light green')
2630
self.button3.grid(row=1, column=2, padx=3, pady=3)
2731
self.button3.config(font=("Arial", 18))
2832

29-
self.button4 = Button(self.root, text="4", width=3, command=lambda:self.ins('4'))
33+
self.button4 = Button(self.root, text="4", width=3, command=lambda:self.ins('4'),relief=RAISED,bg='light green')
3034
self.button4.grid(row=2, column=0, padx=3, pady=3)
3135
self.button4.config(font=("Arial", 18))
3236

33-
self.button5 = Button(self.root, text="5", width=3, command=lambda:self.ins('5'))
37+
self.button5 = Button(self.root, text="5", width=3, command=lambda:self.ins('5'),relief=RAISED,bg='light green')
3438
self.button5.grid(row=2, column=1, padx=3, pady=3)
3539
self.button5.config(font=("Arial", 18))
3640

37-
self.button6 = Button(self.root, text="6", width=3, command=lambda:self.ins('6'))
41+
self.button6 = Button(self.root, text="6", width=3, command=lambda:self.ins('6'),relief=RAISED,bg='light green')
3842
self.button6.grid(row=2, column=2, padx=3, pady=3)
3943
self.button6.config(font=("Arial", 18))
4044

41-
self.button7 = Button(self.root, text="7", width=3, command=lambda:self.ins('7'))
45+
self.button7 = Button(self.root, text="7", width=3, command=lambda:self.ins('7'),relief=RAISED,bg='light green')
4246
self.button7.grid(row=3, column=0, padx=3, pady=3)
4347
self.button7.config(font=("Arial", 18))
4448

45-
self.button8 = Button(self.root, text="8", width=3, command=lambda:self.ins('8'))
49+
self.button8 = Button(self.root, text="8", width=3, command=lambda:self.ins('8'),relief=RAISED,bg='light green')
4650
self.button8.grid(row=3, column=1, padx=3, pady=3)
4751
self.button8.config(font=("Arial", 18))
4852

49-
self.button9 = Button(self.root, text="9", width=3, command=lambda:self.ins('9'))
53+
self.button9 = Button(self.root, text="9", width=3, command=lambda:self.ins('9'),relief=RAISED,bg='light green')
5054
self.button9.grid(row=3, column=2, padx=3, pady=3)
5155
self.button9.config(font=("Arial", 18))
5256

53-
self.button0 = Button(self.root, text="0", width=3, command=lambda: self.ins('0'))
57+
self.button0 = Button(self.root, text="0", width=3, command=lambda: self.ins('0'),relief=RAISED,bg='light green')
5458
self.button0.grid(row=4, column=0, padx=3, pady=3)
5559
self.button0.config(font=("Arial", 18))
5660

57-
self.button_open = Button(self.root, text="(", width=3, command=lambda: self.ins('('))
61+
self.button_open = Button(self.root, text="(", width=3, command=lambda: self.ins('('),relief=RAISED)
5862
self.button_open.grid(row=4, column=1, padx=3, pady=3)
5963
self.button_open.config(font=("Arial", 18))
6064

61-
self.button_close = Button(self.root, text=")", width=3, command=lambda: self.ins(')'))
65+
self.button_close = Button(self.root, text=")", width=3, command=lambda: self.ins(')'),relief=RAISED)
6266
self.button_close.grid(row=4, column=2, padx=3, pady=3)
6367
self.button_close.config(font=("Arial", 18))
6468

6569
# Operations Buttons
6670

67-
self.buttonplus = Button(self.root, text="+", width=3, command=lambda:self.ins('+'))
71+
self.buttonplus = Button(self.root, text="+", width=3, command=lambda:self.ins('+'),relief=RAISED)
6872
self.buttonplus.grid(row=1, column=3, padx=3, pady=3)
6973
self.buttonplus.config(font=("Arial", 18))
7074

71-
self.buttonminus = Button(self.root, text="-", width=3, command=lambda:self.ins('-'))
75+
self.buttonminus = Button(self.root, text="-", width=3, command=lambda:self.ins('-'),relief=RAISED)
7276
self.buttonminus.grid(row=1, column=4, padx=3, pady=3)
7377
self.buttonminus.config(font=("Arial", 18))
7478

75-
self.buttondivide = Button(self.root, text="/", width=3, command=lambda:self.ins('/'))
79+
self.buttondivide = Button(self.root, text="/", width=3, command=lambda:self.ins('/'),relief=RAISED)
7680
self.buttondivide.grid(row=2, column=3, padx=3, pady=3)
7781
self.buttondivide.config(font=("Arial", 18))
7882

79-
self.buttonmultiply = Button(self.root, text="*", width=3, command=lambda:self.ins('*'))
83+
self.buttonmultiply = Button(self.root, text="*", width=3, command=lambda:self.ins('*'),relief=RAISED)
8084
self.buttonmultiply.grid(row=2, column=4, padx=3, pady=3)
8185
self.buttonmultiply.config(font=("Arial", 18))
8286

83-
self.buttoncancel = Button(self.root, text="C", width=3, command=lambda: self.cancel())
87+
self.buttoncancel = Button(self.root, text="C", width=3, command=lambda: self.cancel(),relief=RAISED,bg='#EF5350',fg='white')
8488
self.buttoncancel.grid(row=3, column=4, padx=3, pady=3)
8589
self.buttoncancel.config(font=("Arial", 18))
8690

87-
self.buttondeleteall = Button(self.root, text="Del", width=3, command=lambda: self.delete_all())
91+
self.buttondeleteall = Button(self.root, text="Del", width=3, command=lambda: self.delete_all(),relief=RAISED)
8892
self.buttondeleteall.grid(row=3, column=3, padx=3, pady=3)
8993
self.buttondeleteall.config(font=("Arial", 18))
9094

91-
self.buttonresult = Button(self.root, text="=", width=6, command=lambda:self.calculate())
95+
self.buttonresult = Button(self.root, text="=", width=7, command=lambda:self.calculate(),relief=RAISED,bg='#FFEE58')
9296
self.buttonresult.grid(row=4, column=3, padx=3, pady=3, columnspan=2)
9397
self.buttonresult.config(font=("Arial", 18))
9498

0 commit comments

Comments
 (0)