-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcalculator.py
106 lines (63 loc) · 2.42 KB
/
calculator.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
106
from tkinter import *
from math import *
import time
root = Tk()
def write(button):
global eNum, bt1, bt2, bt3, bt4, bt5, bt6, bt7, bt8, bt9, bt0
eNum.insert(END, int(button.cget('text')))
def add():
global eNum
eNum.insert(END, '+')
def sub():
global eNum
eNum.insert(END, '-')
def multi():
global eNum
eNum.insert(END, '*')
def div():
global eNum
eNum.insert(END, '/')
def equal():
global eNum
number = eNum.get()
integers = eval(number)
strint = integers
eNum.destroy()
eNum = Entry(root, width = 35)
eNum.grid(row = 1, column = 0, columnspan = 5)
eNum.insert(END, strint)
blank1 = Label(root, text = '')
blank1.grid(row = 0, column = 0)
eNum = Entry(root, width = 35)
eNum.grid(row = 1, column = 0, columnspan = 5)
bt1 = Button(root, text = '1', height = 5, width = 10, command = lambda: write(bt1))
bt1.grid(row = 4, column = 0)
bt2 = Button(root, text = '2', height = 5, width = 10, command = lambda: write(bt2))
bt2.grid(row = 4, column = 1)
bt3 = Button(root, text = '3', height = 5, width = 10, command = lambda: write(bt3))
bt3.grid(row = 4, column = 2)
bt4 = Button(root, text = '4', height = 5, width = 10, command = lambda: write(bt4))
bt4.grid(row = 3, column = 0)
bt5 = Button(root, text = '5', height = 5, width = 10, command = lambda: write(bt5))
bt5.grid(row = 3, column = 1)
bt6 = Button(root, text = '6', height = 5, width = 10, command = lambda: write(bt6))
bt6.grid(row = 3, column = 2)
bt7 = Button(root, text = '7', height = 5, width = 10, command = lambda: write(bt7))
bt7.grid(row = 2, column = 0)
bt8 = Button(root, text = '8', height = 5, width = 10, command = lambda: write(bt8))
bt8.grid(row = 2, column = 1)
bt9 = Button(root, text = '9', height = 5, width = 10, command = lambda: write(bt9))
bt9.grid(row = 2, column = 2)
bt0 = Button(root, text = '0', height = 5, width = 10, command = lambda: write(bt0))
bt0.grid(row = 5, column = 1)
btplus = Button(root, text = '+', height = 5, width = 10, command = add)
btplus.grid(row = 5, column = 0)
btminus = Button(root, text = '-', height = 5, width = 10, command = sub)
btminus.grid(row = 5, column = 2)
btmulti = Button(root, text = '*', height = 5, width = 10, command = multi)
btmulti.grid(row = 6, column = 0)
btdiv = Button(root, text = '÷', height = 5, width = 10, command = div)
btdiv.grid(row = 6, column = 2)
btequal = Button(root, text = '=', height = 5, width = 10, command = equal)
btequal.grid(row = 6, column = 1)
mainloop()