Python Tkinter program to add two numbers

In this program, you will learn how to add two numbers using Tkinter in Python.

30 = 10 + 20 

20 = 10 + 10 

b1 = Button(tk, text="Click", command=display).place(x=100, y=100)

Example: How to add two numbers using Tkinter in Python

import tkinter as tk
from functools import partial

def findsum(l3, num1, num2):
    n1 = int(num1.get())
    n2 = int(num2.get())
    n3 = n1 + n2
    l3.config(text="Result = %d" % n3)

root = tk.Tk()

number1 = tk.StringVar()
number2 = tk.StringVar()

l1 = tk.Label(root, text="Enter 1st number").place(x=20, y=60)
l2 = tk.Label(root, text="Enter 2nd number").place(x=20, y=120)
t1 = tk.Entry(root, textvariable=number1).place(x=200, y=60)
t2 = tk.Entry(root, textvariable=number2).place(x=200, y=120)

labelResult = tk.Label(root), y=200)

findsum = partial(findsum, labelResult, number1, number2)

b1 = tk.Button(root, text="ADD", command=findsum).place(x=200, y=300)
b2 = tk.Button(root, text="Cancel", command=root.destroy).place(x=250, y=300)



Xiith is created for educational, experimental, and schooling purpose. Examples on Xiith are made easier to make a better or basic understanding. Tutorials, testimonials, and examples are continuously checked to avoid delusion, but we cannot take complete responsibility of all programs on Xiith. When you are operating this site, you have to agree to read and accept our terms of use, cookie and privacy policy.Copyright © 2020 by Xiith. All Rights Reserved. About us.