# Find Difference Between Two Numbers Using Python

Body
A tutorial that tackles Find Difference Between Two Numbers Using Python. Throughout the tutorial you will learn how to use python language easily. This program will calculate the difference between the two given numbers. You can tweak this program and use this to any python program you have.

## Importing Modules

After setting up the installation and the database, run the IDLE and click file and then new file. After that a new window will appear containing a black file this will be the text editor for the python. Then copy code that I provided below and paste it inside the IDLE text editor.
`from tkinter import *`

## Setting up the Main Frame

After importing the modules, we will now then create the main frame for the application. To do that just copy the code below and paste it inside the IDLE text editor.
`root = Tk()root.title("Find Difference Between Two Numbers Using Python")width = 400height = 280screen_width = root.winfo_screenwidth()screen_height = root.winfo_screenheight()x = (screen_width/2) - (width/2)y = (screen_height/2) - (height/2)root.geometry("%dx%d+%d+%d" % (width, height, x, y))root.resizable(0, 0)`

## Designing the Layout

After creating the Main Frame we will now add some layout to the application. Just kindly copy the code below and paste it inside the IDLE text editor.
`#==============================FRAMES=========================================Top = Frame(root, bd=2,  relief=RIDGE)Top.pack(side=TOP, fill=X)Form = Frame(root, height=200)Form.pack(side=TOP, pady=20) #==============================LABELS=========================================lbl_title = Label(Top, text = "Find Difference Between Two Numbers Using Python", font=('arial', 12))lbl_title.pack(fill=X)lbl_num1 = Label(Form, text = "Number 1:", font=('arial', 14), bd=15)lbl_num1.grid(row=0, sticky="e")lbl_num2 = Label(Form, text = "Number 2:", font=('arial', 14), bd=15)lbl_num2.grid(row=1, sticky="e")lbl_text = Label(Form)lbl_text.grid(row=2, columnspan=2) #==============================ENTRY WIDGETS==================================num1 = Entry(Form, font=(14))num1.grid(row=0, column=1)num2 = Entry(Form, font=(14))num2.grid(row=1, column=1) #==============================BUTTON WIDGETS=================================btn_calculate = Button(Form, text="Calculate", width=45, command=calculate)btn_calculate.grid(pady=25, row=3, columnspan=2)`

## Creating the Main Function

This is where the code that contains the main function of the application. This code will sum both give numbers when the button is clicked. To do that just copy and write these blocks of code.
`#==============================METHODS========================================def calculate():    if not num1.get() and not num2.get():        print("Please enter a number")    else:        diff=int(num1.get())-int(num2.get())        lbl_text.config(text = "The answer is %d" % (diff))        num1.set=""        num2.set=""`
There you have it we just created a Find Difference Between Two Numbers using Python. I hope that this simple tutorial help you for what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!!