33window .title ("Standard Binary Calculator" )
44window .resizable (0 , 0 )
55
6- #lets create binary didgits
6+ #lets create binary digits for more clear to calculator
77def f1 ():
88 s = e1_val .get ()
99 e1 .delete (first = 0 , last = len (s ))
@@ -14,7 +14,7 @@ def f3():
1414 s = e1_val .get ()
1515 e1 .insert (END , "0" )
1616
17- #this loop is for the -, +, / and * operators
17+ #this loop is for the -, +, / and * operators so that whenever the user is giving the below operations, it will work accordingly.
1818def f4 ():
1919 x = 0
2020 s = e1_val .get ()
@@ -35,7 +35,7 @@ def f4():
3535 e1 .insert (END , "" )
3636 e1 .insert (END , str (x ))
3737
38-
38+ #this is for dividing the two binary numbers.
3939def bin_to_dec (n ):
4040 num = n
4141 dec_value = 0
@@ -49,15 +49,15 @@ def bin_to_dec(n):
4949 base = base * 2
5050 return dec_value
5151
52- #now, will add
52+ #now, will add the two binary numbers.
5353def add (x , y ):
5454 a = bin_to_dec (x )
5555 b = bin_to_dec (y )
5656 c = a + b
5757 d = bin (c ).replace ("0b" , "" )
5858 return d
5959
60- #this is for -
60+ #this is for - operation for two binary numbers.
6161def sub (x , y ):
6262 a = bin_to_dec (x )
6363 b = bin_to_dec (y )
@@ -70,6 +70,8 @@ def f5():
7070 x = 0
7171 s = e1_val .get ()
7272 flag = 1
73+
74+ #from the operations : -, +, * or / if the operation is `+` then do the work or else end the loop.
7375 for i in range (0 , len (s )):
7476 if s [i ] == '/' or s [i ] == 'X' or s [i ] == '+' or s [i ] == '-' :
7577 flag = 0
@@ -88,7 +90,7 @@ def f5():
8890 e1 .insert (END , str (x ))
8991 e1 .insert (END , "+" )
9092
91-
93+ #from the operations : -, +, * or / if the operation is `-` then do the work or else end the loop.
9294def f6 ():
9395 x = 0
9496 s = e1_val .get ()
@@ -111,7 +113,7 @@ def f6():
111113 e1 .insert (END , str (x ))
112114 e1 .insert (END , "-" )
113115
114-
116+ #from the operations : -, +, * or / if the operation is `/` then do the work or else end the loop.
115117def f7 ():
116118 x = 0
117119 s = e1_val .get ()
@@ -134,7 +136,7 @@ def f7():
134136 e1 .insert (END , str (x ))
135137 e1 .insert (END , "/" )
136138
137-
139+ #from the operations : -, +, * or / if the operation is `*` then do the work or else end the loop.
138140def f8 ():
139141 x = 0
140142 s = e1_val .get ()
@@ -157,11 +159,14 @@ def f8():
157159 e1 .insert (END , str (x ))
158160 e1 .insert (END , "X" )
159161
160- #creating gui
162+ #creating gui for the calculator .
163+
164+ #firstly, creating a space
161165e1_val = StringVar ()
162166e1 = Entry (window , textvariable = e1_val , width = 50 )
163167e1 .grid (row = 0 , column = 0 , columnspan = 4 )
164168
169+ # adding the buttons will give colours to the calculator.
165170b1 = Button (window , text = "1" , width = 8 , height = 2 , command = f2 ,bg = 'lightblue' , fg = 'white' )
166171b1 .grid (row = 1 , column = 0 )
167172
@@ -186,5 +191,5 @@ def f8():
186191bdiv = Button (window , text = "/" , width = 8 , height = 2 , command = f7 ,bg = 'lightpink' , fg = 'white' )
187192bdiv .grid (row = 2 , column = 3 )
188193
189- #ending the loop
194+ #ending the loop and it will run until it is false.
190195window .mainloop ()
0 commit comments