Programming Examples
Tkinter program to add two number
Tkinter Program to Create a GUI to accept two integer number form user and print its sum.
Solution
from tkinter import *
from tkinter import messagebox
root=Tk()
root.geometry("250x300")
Label(root,text="Sum of 2 No",font="arial 14 bold").grid(row=0,columnspan=2)
Label(root,text="").grid(row=1,column=0)
Label(root,text="Number 1 ").grid(row=2,column=0)
Label(root,text="").grid(row=3,column=0)
Label(root,text="Number 2 ").grid(row=4,column=0)
Label(root,text="").grid(row=5,column=0)
Label(root,text="Result ").grid(row=6,column=0)
Label(root,text="").grid(row=7,column=0)
v1=StringVar()
v2=StringVar()
v3=StringVar()
e1=Entry(root,textvariable=v1).grid(row=2,column=1)
e2=Entry(root,textvariable=v2).grid(row=4,column=1)
e3=Entry(root,textvariable=v3).grid(row=6,column=1)
def sum():
a=int(v1.get())
b=int(v2.get())
c=a+b
v3.set(c)
Button(root,text="Sum",command=sum).grid(row=8,column=1)
root.mainloop()
Output