Python Program for Arithmetic Opeartions using Python GUI
How to create Python GUI ?
A simple way to create the GUI in Python by using the Tkinter Library of Python.
Tkinter provides a fast and easy way to create the GUI applications in Python. Tkinter provides a powerfull object oriented interface to the Tk GUI Toolkit.
Example :
import tkinter # imported tkinter
win = tkinter.Tk() # object Creation
win.title("My Window") # Title of the Window
win.mainloop() # run the tkinter
Here we have created a simple window by using tkinter library.
In that, we have create a object of tkinter package as win.
Then, we have gave the title to window by using .title() method.
Output :
from tkinter import *
def addition():
result = float(bx1.get())+float(bx2.get())
result = round(result,4)
lbl4.config(text=result)
def subtract():
result = float(bx1.get())-float(bx2.get())
result = round(result,4)
lbl4.config(text=result)
def multiply():
result = float(bx1.get())*float(bx2.get())
result = round(result,4)
lbl4.config(text=result)
def divide():
result = float(bx1.get())/float(bx2.get())
result = round(result,4)
lbl4.config(text=result)
window = Tk()
window.title("Python Calculator")
lbl1 = Label(window,text="Enter 1st Number : ")
lbl1.grid(row=0, column=0)
lbl2 = Label(window, text="Enter 2nd Number : ")
lbl2.grid(row=1, column=0)
lbl3 = Label(window,text="Result : ")
lbl3.grid(row=2, column=0)
lbl4 = Label(window,text="")
lbl4.grid(row=2,column=1)
bx1 = Entry(window)
bx2 = Entry(window)
bx1.grid(row=0, column=1)
bx2.grid(row=1, column=1)
b1 = Button(window, text="Addition", width=10, command=addition)
b1.grid(row=0, column=2, padx=5, pady=5)
b2 = Button(window, text="Subtract", width=10, command=subtract)
b2.grid(row=0, column=3, padx=5, pady=5)
b3 = Button(window, text="Multiply", width=10, command=multiply)
b3.grid(row=1, column=2, padx=5, pady=5)
b4 = Button(window, text="Divide", width=10, command=divide)
b4.grid(row=1,column=3,padx=5,pady=5)
lbl5 = Label(text="www.computertipstricks.tech for Python GUI Tutorial",
bg='lightgreen',font=('verdana',12))
lbl5.grid(row=4, column=0, padx=5, pady=5, columnspan=4)
window.mainloop()
0 Comments
Please do not add Any Spam link in Comments !