-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
90 lines (75 loc) · 2.61 KB
/
test.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
from tkinter import *
import tkinter
from tkinter import messagebox
#functions
def entry_delete():
ent.delete(0, END)
def addition():
global f_num
f_num = ent.get()
global math
math = "Addition"
ent.delete(0, END)
def subtraction():
global f_num
f_num = ent.get()
global math
math = "Subtraction"
ent.delete(0, END)
def division():
global f_num
f_num = ent.get()
global math
math = "Division"
ent.delete(0, END)
def multiplication():
global f_num
f_num = ent.get()
global math
math = "Multiplication"
ent.delete(0, END)
def equals():
second_number = ent.get()
ent.delete(0, END)
try:
if math == "Addition":
ent.insert(0, int(f_num) + int(second_number))
elif math == "Subtraction":
ent.insert(0, int(f_num) - int(second_number))
elif math == "Division":
ent.insert(0, int(f_num) / int(second_number))
elif math == "Multiplication":
ent.insert(0, int(f_num) * int(second_number))
else:
pass
except ValueError:
messagebox.showwarning("Error", "Please input interger values")
#setup
colours = ["aquamarine3", "Red", "Black", "Yellow", "aqua"]
surface = tkinter.Tk()
surface.title("Calculator")
surface.geometry("550x300")
surface.configure(bg=colours[0])
#widgets
ent = tkinter.Entry(surface, bd=2, width=35, bg=colours[3], fg=colours[2])
ent.grid(row=0,column=1, columnspan=2)
#buttons
btn1 = tkinter.Button(surface, text="+", padx=60, pady=30, bg=colours[4],
activebackground=colours[1], command=addition)
btn2 = tkinter.Button(surface, text="-", padx=60, pady=30, bg=colours[4],
activebackground=colours[1], command=subtraction)
btn3 = tkinter.Button(surface, text="X", padx=60, pady=30, bg=colours[4],
activebackground=colours[1], command=multiplication)
btn4 = tkinter.Button(surface, text="/", padx=60, pady=30, bg=colours[4],
activebackground=colours[1], command=division)
btn5 = tkinter.Button(surface, text="=", padx=60, pady=30, bg=colours[4],
activebackground=colours[1], command=equals)
btn6 = tkinter.Button(surface, text="Clear", padx=60, pady=30, bg=colours[4],
activebackground=colours[1], command=entry_delete)
btn1.grid(row=1, column=0)
btn2.grid(row=1, column=1)
btn3.grid(row=1, column=2)
btn4.grid(row=1, column=3)
btn5.grid(row=2, column=0, columnspan=2)
btn6.grid(row=2, column=2, columnspan=2)
surface.mainloop()