A simple program to ask the user to give two numbers and then the program will compute the sum of two numbers using a graphical user interface using Python programming language.
I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in the following email address for further details. If you want to advertise on my website kindly contact me also in my email address also. Thank you.
My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.
My mobile number here in the Philippines is 09173084360.
Please subscribe to my channel https://www.youtube.com/channel/UCOs-lpOoIeJoh6gpJthPoGg
Program Listing
from tkinter import *
root = Tk()
root.title("Addition of Two Numbers Using GUI in Python")
width = 600
height = 300
screen_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(False,False)
#==============================METHODS========================================
def add():
if not num1.get() and not num2.get():
print("Please enter a number")
else:
res=int(num1.get())+int(num2.get())
lbl_text.config(text = "The answer is %d" % (res))
num1.set=""
num2.set=""
#==============================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 = "Addition of Two Numbers Using GUI in Python", font=('arial', 16))
lbl_title.pack(fill=X)
lbl_num1 = Label(Form, text = "Enter First Value:", font=('arial', 14), bd=15)
lbl_num1.grid(row=0, sticky="e")
lbl_num2 = Label(Form, text = "Enter Second Value:", 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="Add", width=45, command=add)
btn_calculate.grid(pady=25, row=3, columnspan=2)
root.mainloop()