Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
3.2 kB
3
Indexable
Never
from tkinter import*
from tkinter import messagebox
from tkinter.messagebox import askyesno
a=Tk()

a.title("Calculator")
a.configure(bg="light cyan")
lb=Label(a,text='')
lb.grid(column=0,row=9)
v=''
def f1():
   lb.configure(text='1')
   global v
   v=v+'1'

def f2():
   lb.configure(text='2')
   global v
   v=v+' 2'

def f3():
   lb.configure(text='3')
   global v
   v=v+'3'
def f4():
   lb.configure(text='+')
   global v
   v=v+' +'

def f5():
   lb.configure(text='4')
   global v
   v=v+' 4'
def f6():
   lb.configure(text='5')
   global v
   v=v+' 5'

def f7():
   lb.configure(text='6')
   global v
   v=v+' 6'

def f8():
   lb.configure(text='-')
   global v
   v=v+' -'


def f9():
   lb.configure(text='7')
   global v
   v=v+' 7'

def f10():
   lb.configure(text='8')
   global v
   v=v+' 8'

def f11():
   lb.configure(text='9')
   global v
   v=v+' 9'

def f12():
   lb.configure(text='*')
   global v
   v=v+' *'

def f13():
   lb.configure(text='c')
   global v
   v=''


def f14():
   lb.configure(text='0')
   global v
   v=v+' 0'


def f15():
   lb.configure(text='=')
   global v
   a=eval(v)
   lb.configure(text=v+' = '+str(a))

def f16():
   lb.configure(text='/')
   global v
   v=v+' /'

b1=Button(a,text='1',command=f1)
b1.grid(column=0,row=1)
lb1=Label(a,text='',bg="light cyan")
lb1.grid(column=1,row=1)

b2=Button(a,text='2',command=f2)
b2.grid(column=2,row=1)
lb2=Label(a,text='',bg="light cyan")
lb2.grid(column=3,row=1)

b3=Button(a,text='3',command=f3)
b3.grid(column=4,row=1)
lb3=Label(a,text='',bg="light cyan")
lb3.grid(column=5,row=1)

b4=Button(a,text='+',command=f4)
b4.grid(column=6,row=1)
lb4=Label(a,text='',bg="light cyan")
lb4.grid(column=7,row=1)

b5=Button(a,text='4',command=f5)
b5.grid(column=0,row=2)
lb5=Label(a,text='',bg="light cyan")
lb5.grid(column=1,row=2)

b6=Button(a,text='5',command=f6)
b6.grid(column=2,row=2)
lb6=Label(a,text='',bg="light cyan")
lb6.grid(column=3,row=2)

b7=Button(a,text='6',command=f7)
b7.grid(column=4,row=2)
lb7=Label(a,text='',bg="light cyan")
lb7.grid(column=5,row=2)

b8=Button(a,text='-',command=f8)
b8.grid(column=6,row=2)
lb8=Label(a,text='',bg="light cyan")
lb8.grid(column=7,row=2)

b9=Button(a,text='7',command=f9)
b9.grid(column=0,row=3)
lb9=Label(a,text='',bg="light cyan")
lb9.grid(column=1,row=3)

b10=Button(a,text='8',command=f10)
b10.grid(column=2,row=3)
lb10=Label(a,text='',bg="light cyan")
lb10.grid(column=3,row=3)

b11=Button(a,text='9',command=f11)
b11.grid(column=4,row=3)
lb11=Label(a,text='',bg="light cyan")
lb11.grid(column=5,row=3)

b12=Button(a,text='*',command=f12)
b12.grid(column=6,row=3)
lb12=Label(a,text='',bg="light cyan")
lb12.grid(column=7,row=3)

b13=Button(a,text='c',command=f13)
b13.grid(column=0,row=4)
lb13=Label(a,text='',bg="light cyan")
lb13.grid(column=1,row=4)

b14=Button(a,text='0',command=f14)
b14.grid(column=2,row=4)
lb14=Label(a,text='',bg="light cyan")
lb14.grid(column=3,row=4)

b14=Button(a,text='=',command=f15)
b14.grid(column=4,row=4)
lb14=Label(a,text='',bg="light cyan")
lb14.grid(column=5,row=4)

b14=Button(a,text='/',command=f16)
b14.grid(column=6,row=4)
lb14=Label(a,text='',bg="light cyan")
lb14.grid(column=7,row=4)
a.mainloop()