*****************NAME- ANIKET - I2 -39*********************
Experiment No.11A
Aim: Write python programs to understand GUI designing using Tkinter.
Program Code:
from tkinter import *
window=Tk()
window.title("Calculator")
window.geometry("350x270")
expression=""
def click(item):
global expression
expression=expression+str(item)
equation.set(expression)
def equal():
try:
global expression
result=str(eval(expression))
equation.set(result)
expression=""
except:
equation.set(" ERROR ")
expression=""
def clear():
global expression
equation.set("")
expression=""
equation=StringVar()
expression_field=Entry(window,textvariable=equation,font=('arial',20,'bold'))
expression_field.grid(columnspan=50,ipadx=100,ipady=30)
button1=Button(window,text='7',command=lambda:click(7),height=2,width=10,activ
ebackground="red",padx=1,pady=1)
button1.grid(row=2,column=0)
button2=Button(window,text='8',command=lambda:click(8),height=2,width=10,activ
ebackground="red",padx=1,pady=1)
button2.grid(row=2,column=1)
button3=Button(window,text='9',command=lambda:click(9),height=2,width=10,activ
ebackground="red",padx=1,pady=1)
button3.grid(row=2,column=2)
button4=Button(window,text='+',command=lambda:click("+"),height=2,width=10,act
ivebackground="red",padx=1,pady=1)
button4.grid(row=2,column=3)
button5=Button(window,text='4',command=lambda:click(4),height=2,width=10,activ
ebackground="red",padx=1,pady=1)
button5.grid(row=3,column=0)
button6=Button(window,text='5',command=lambda:click(5),height=2,width=10,activ
ebackground="red",padx=1,pady=1)
button6.grid(row=3,column=1)
button7=Button(window,text='6',command=lambda:click(6),height=2,width=10,activ
ebackground="red",padx=1,pady=1)
button7.grid(row=3,column=2)
button8=Button(window,text='-',command=lambda:click("-"),height=2,width=10,acti
vebackground="red",padx=1,pady=1)
button8.grid(row=3,column=3)
button9=Button(window,text='1',command=lambda:click(1),height=2,width=10,activ
ebackground="red",padx=1,pady=1)
button9.grid(row=4,column=0)
button10=Button(window,text='2',command=lambda:click(2),height=2,width=10,acti
vebackground="red",padx=1,pady=1)
button10.grid(row=4,column=1)
button11=Button(window,text='3',command=lambda:click(3),height=2,width=10,acti
vebackground="red",padx=1,pady=1)
button11.grid(row=4,column=2)
button12=Button(window,text='*',command=lambda:click("*"),height=2,width=10,a
ctivebackground="red",padx=1,pady=1)
button12.grid(row=4,column=3)
button13=Button(window,text='0',command=lambda:click(0),height=2,width=10,acti
vebackground="red",padx=1,pady=1)
button13.grid(row=5,column=0)
button14=Button(window,text='=',command=lambda:equal(),height=2,width=10,acti
vebackground="red",padx=1,pady=1)
button14.grid(row=5,column=1)
button15=Button(window,text='Clear',command=lambda:clear(),height=2,width=10,a
ctivebackground="red",padx=1,pady=1)
button15.grid(row=5,column=2)
button16=Button(window,text='/',command=lambda:click("/"),height=2,width=10,act
ivebackground="red",padx=1,pady=1)
button16.grid(row=5,column=3)
window.mainloop()
Input:
Output:
Conclusion: Hence we have successfully executed the given problem
statement.
Lab Outcome: Explain how to design GUI Applications in Python and
evaluate different database operations.