Ratio Calculator GUI using Tkinter


In this article, we will see how to create a functional application that calculates the ratio. In order to make it fully functional, we will use SpinBox method that generally creates an ideal spinner for a value. This value can be modified using the spinner widget in the frame. Thus, a SpinBox object takes values in the range from minimum to maximum.

First, we will create a tkinter frame inside which we will define some widgets.


from tkinter import *
win = Tk()

win.title("Ratio Calculator")
#Create text Label for Ratio Calculator

label= Label(win, text="Ratio Calculator", font=('Times New Roman', 25))

#Define the function to calculate the value

def ratio_cal():
   b1= int(b.get())
   c1= int(c.get())

   val= (b1*c1)/a1


#Add another frame
frame= Frame(win)

#Create Spin Boxes for A B and C

a= Spinbox(frame, from_=0, to= 100000, font=('Times New Roman', 14), width=10)
a.pack(side=LEFT,padx=10, pady=10)

b= Spinbox(frame,from_=0, to=100000, font=('Times New Roman', 14), width=10)
b.pack(side=LEFT, padx= 10, pady=10)

c= Spinbox(frame, from_=0, to=100000, font=('Times New Roman', 14), width= 10)
c.pack(side= LEFT, padx=10, pady=10)

x_val= Label(frame, text="",font=('Times New Roman', 18))

#Create a Button to calculate the result

Button(win, text= "Calculate",command=ratio_cal, borderwidth=3, fg="white",
bg="black", width=15).pack(pady=20)



Running the above code will create a GUI-based Ratio Calculator.

Published on 06-Mar-2021 13:30:38