How to make Gui using python

How to make Gui using python

Python Gui Calculator Python Tuition in Kolkata DBC Tutorial

Computer tuition in Kolkata

from tkinter import *
win=Tk()
win.title("My calculator")

win.geometry("360x500+500+300")


data=StringVar()
val=""

def btnclick(number):
global val
val=val+str(number)
data.set(val)

def btnequal():
global val
result=str(eval(val))
data.set(result)
def btnclear():
global val
val=" "
data.set(" ")




display=Entry(win,bd=20,bg="yellow",font=("Arial",20),justify="right",width=20,textvariable=data)



display.grid(row=0,column=0,columnspan=4)
btn7=Button(win,text="7",font=("Arial",10,"bold"),bd=12,height=2,width=7,command=lambda:btnclick(7))

btn7.grid(row=1,column=0)

btn8=Button(win,text="8",font=("Arial",10,"bold"),bd=12,height=2,width=7,command=lambda:btnclick(8))

btn8.grid(row=1,column=1)
btn9=Button(win,text="9",font=("Arial",10,"bold"),bd=12,height=2,width=7,command=lambda:btnclick(9))

btn9.grid(row=1,column=2)
btn4=Button(win,text="4",font=("Arial",10,"bold"),bd=12,height=2,width=7,command=lambda:btnclick(4))

btn4.grid(row=2,column=0)
btn5=Button(win,text="5",font=("Arial",10,"bold"),bd=12,height=2,width=7,command=lambda:btnclick(5))

btn5.grid(row=2,column=1)
btn6=Button(win,text="6",font=("Arial",10,"bold"),bd=12,height=2,width=7,command=lambda:btnclick(6))

btn6.grid(row=2,column=2)
btn1=Button(win,text="1",font=("Arial",10,"bold"),bd=12,height=2,width=7,command=lambda:btnclick(1))

btn1.grid(row=3,column=0)
btn2=Button(win,text="2",font=("Arial",10,"bold"),bd=12,height=2,width=7,command=lambda:btnclick(2))

btn2.grid(row=3,column=1)

btn3=Button(win,text="3",font=("Arial",10,"bold"),bd=12,height=2,width=7,command=lambda:btnclick(3))

btn3.grid(row=3,column=2)

btn0=Button(win,text="0",font=("Arial",10,"bold"),bd=12,height=2,width=7,command=lambda:btnclick(0))

btn0.grid(row=4,column=1)

btnclear=Button(win,text="C",font=("Arial",10,"bold"),bd=12,height=2,width=7,command=btnclear)

btnclear.grid(row=4,column=0)
btnequal=Button(win,text="=",font=("Arial",10,"bold"),bd=12,height=2,width=7,command=btnequal)

btnequal.grid(row=6,column=0)

btnadd=Button(win,text="+",font=("Arial",10,"bold"),bd=12,height=2,width=7,command=lambda:btnclick("+"))

btnadd.grid(row=5,column=0)


btnmul=Button(win,text="x",font=("Arial",10,"bold"),bd=12,height=2,width=7,command=lambda:btnclick("*"))

btnmul.grid(row=5,column=1)

btndiv=Button(win,text="/",font=("Arial",10,"bold"),bd=12,height=2,width=7,command=lambda:btnclick("/"))

btndiv.grid(row=5,column=2)

btnsub=Button(win,text="-",font=("Arial",10,"bold"),bd=12,height=2,width=7,command=lambda:btnclick("-"))

btnsub.grid(row=4,column=2)



win.mainloop()



0Shares