-
Notifications
You must be signed in to change notification settings - Fork 0
/
cal.py
59 lines (47 loc) · 3.36 KB
/
cal.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
from tkinter import *
import math
def btn_Click(numbers):
global operator
operator=operator + str(numbers)
text_input.set(operator)
def btnclrDisplay():
global operator
operator=""
text_input.set("")
def delete():
global operator
text_input.set(text_input.get() [:-1])
def btn_Equ():
global operator
sumup=str(eval(operator))
text_input.set(sumup)
operator=""
cal=Tk()
cal.title("calculator")
cal.geometry("451x621")
cal.resizable(0,0)
operator=""
text_input = StringVar()
cal.config(background="skyblue")
textDisplay=Entry(cal,font=("arial",20,'bold'), textvariable=text_input ,bd=50,insertwidth=4,bg="powder blue",justify="right").grid(columnspan=5)
btnclr=Button(cal,padx=16,bd=20,bg="purple",fg="black",font=("arial",20,'bold'),text="C",command=btnclrDisplay).grid(row=1,column=0)
PER=Button(cal,padx=16,bd=20,bg="purple",fg="black",font=("arial",20,'bold'),text="%",command=lambda:btn_Click("%")).grid(row=1,column=1)
DEL=Button(cal,padx=16,bd=20,bg="purple",fg="black",font=("arial",20,'bold'),text="<",command=delete).grid(row=1,column=2)
Div=Button(cal,padx=16,bd=23,fg="black",bg="purple",font=("arial",20,'bold'),text="/",command=lambda:btn_Click("/")).grid(row=1,column=3)
btn7=Button(cal,padx=16,bd=22,bg="blue",fg="black",font=("arial",20,'bold'),text="7",command=lambda:btn_Click(7)).grid(row=2,column=0)
btn8=Button(cal,padx=16,bd=23,bg="blue",fg="black",font=("arial",20,'bold'),text="8",command=lambda:btn_Click(8)).grid(row=2,column=1)
btn9=Button(cal,padx=16,bd=22,bg="blue",fg="black",font=("arial",20,'bold'),text="9",command=lambda:btn_Click(9)).grid(row=2,column=2)
mult=Button(cal,padx=16,bd=21,bg="purple",fg="black",font=("arial",20,'bold'),text="x",command=lambda:btn_Click("*")).grid(row=2,column=3)
btn4=Button(cal,padx=16,bd=22,bg="blue",fg="black",font=("arial",20,'bold'),text="4",command=lambda:btn_Click(4)).grid(row=3,column=0)
btn5=Button(cal,padx=16,bd=23,bg="blue",fg="black",font=("arial",20,'bold'),text="5",command=lambda:btn_Click(5)).grid(row=3,column=1)
btn6=Button(cal,padx=16,bd=22,bg="blue",fg="black",font=("arial",20,'bold'),text="6",command=lambda:btn_Click(6)).grid(row=3,column=2)
sub=Button(cal,padx=16,bd=22,bg="purple",fg="black",font=("arial",20,'bold'),text="-",command=lambda:btn_Click("-")).grid(row=3,column=3)
btn1=Button(cal,padx=16,bd=22,bg="blue",fg="black",font=("arial",20,'bold'),text="1",command=lambda:btn_Click(1)).grid(row=4,column=0)
btn2=Button(cal,padx=16,bd=23,bg="blue",fg="black",font=("arial",20,'bold'),text="2",command=lambda:btn_Click(2)).grid(row=4,column=1)
btn3=Button(cal,padx=16,bd=22,bg="blue",fg="black",font=("arial",20,'bold'),text="3",command=lambda:btn_Click(3)).grid(row=4,column=2)
add=Button(cal,padx=16,bd=21,bg="purple",fg="black",font=("arial",20,'bold'),text="+",command=lambda:btn_Click("+")).grid(row=4,column=3)
dowmbtn=Button(cal,padx=16,bd=21,bg="purple",fg="black",font=("arial",20,'bold'),text="**",command=lambda:btn_Click("**")).grid(row=5,column=0)
btn0=Button(cal,padx=16,bd=23,bg="purple",fg="black",font=("arial",20,'bold'),text="0",command=lambda:btn_Click(0)).grid(row=5,column=1)
deci=Button(cal,padx=16,bd=24,bg="purple",fg="black",font=("arial",20,'bold'),text=".",command=lambda:btn_Click(".")).grid(row=5,column=2)
equal=Button(cal,padx=16,bd=22.5,bg="purple",fg="black",font=("arial",20,'bold'),text="=",command=btn_Equ).grid(row=5,column=3)
cal.mainloop()