-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
105 lines (75 loc) · 3.28 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from tkinter import *
from unittest import result
def buttonClick(number):
global operator
operator = operator + str(number)
input_value.set(operator)
def buttonClear():
global operator
operator = ""
input_value.set("")
def buttonEqual():
global operator
result = str(eval(operator))
input_value.set(result)
operator = ""
main = Tk()
main.title("Calculator")
operator = ""
input_value = StringVar()
display_text = Entry(main, font=("arial", 20, "bold"), textvariable=input_value, bd=30, insertwidth=4,
bg="powder blue", justify=RIGHT)
display_text.grid(columnspan=4)
# Row 1 7 8 9 +
btn_7 = Button(main, padx=16, bd=8, fg="black",
font=("arial", 20, "bold"), text="7", command=lambda: buttonClick(7))
btn_7.grid(row=1, column=0)
btn_8 = Button(main, padx=16, bd=8, fg="black",
font=("arial", 20, "bold"), text="8", command=lambda: buttonClick(8))
btn_8.grid(row=1, column=1)
btn_9 = Button(main, padx=16, bd=8, fg="black",
font=("arial", 20, "bold"), text="9", command=lambda: buttonClick(9))
btn_9.grid(row=1, column=2)
btn_add = Button(main, padx=16, bd=8, fg="black",
font=("arial", 20, "bold"), text="+", command=lambda: buttonClick("+"))
btn_add.grid(row=1, column=3)
# Row 2 - 4 5 6 -
btn_4 = Button(main, padx=16, bd=8, fg="black",
font=("arial", 20, "bold"), text="4", command=lambda: buttonClick(4))
btn_4.grid(row=2, column=0)
btn_5 = Button(main, padx=16, bd=8, fg="black",
font=("arial", 20, "bold"), text="5", command=lambda: buttonClick(5))
btn_5.grid(row=2, column=1)
btn_6 = Button(main, padx=16, bd=8, fg="black",
font=("arial", 20, "bold"), text="6", command=lambda: buttonClick(6))
btn_6.grid(row=2, column=2)
btn_sub = Button(main, padx=16, bd=8, fg="black",
font=("arial", 20, "bold"), text="-", command=lambda: buttonClick("-"))
btn_sub.grid(row=2, column=3)
# Row 3 - 1 2 3 *
btn_1 = Button(main, padx=16, bd=8, fg="black",
font=("arial", 20, "bold"), text="4", command=lambda: buttonClick(1))
btn_1.grid(row=3, column=0)
btn_2 = Button(main, padx=16, bd=8, fg="black",
font=("arial", 20, "bold"), text="5", command=lambda: buttonClick(2))
btn_2.grid(row=3, column=1)
btn_3 = Button(main, padx=16, bd=8, fg="black",
font=("arial", 20, "bold"), text="6", command=lambda: buttonClick(3))
btn_3.grid(row=3, column=2)
btn_mul = Button(main, padx=16, bd=8, fg="black",
font=("arial", 20, "bold"), text="*", command=lambda: buttonClick("*"))
btn_mul.grid(row=3, column=3)
# Row 4 - 0 C = /
btn_0 = Button(main, padx=16, bd=8, fg="black",
font=("arial", 20, "bold"), text="0", command=lambda: buttonClick(0))
btn_0.grid(row=4, column=0)
btn_clear = Button(main, padx=16, bd=8, fg="black",
font=("arial", 20, "bold"), text="C", command=buttonClear)
btn_clear.grid(row=4, column=1)
btn_equal = Button(main, padx=16, bd=8, fg="black",
font=("arial", 20, "bold"), text="=", command=buttonEqual)
btn_equal.grid(row=4, column=2)
btn_div = Button(main, padx=16, bd=8, fg="black",
font=("arial", 20, "bold"), text="/", command=lambda: buttonClick("/"))
btn_div.grid(row=4, column=3)
main.mainloop()